Created
October 15, 2014 14:38
-
-
Save czxttkl/020573f2525fcbeae522 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestAnything { | |
public static void main(String[] args) throws Exception { | |
Object[] a = new Object[2]; | |
a[0] = (Object)"aaaa"; | |
a[1] = (Object)"bbbb"; | |
String[] b = convertLsy(a, String.class); | |
} | |
private static <T> T[] convertLsy(Object[] a, Class<T> cls) { | |
T[] b = (T[])Array.newInstance(cls, a.length); | |
b = (T[])a; | |
return b; | |
} | |
private static <T> T[] convertCzx(Object[] a, Class cls) { | |
T[] b = (T[])Array.newInstance(cls, a.length); | |
for (int i = 0; i < a.length; i++) { | |
b[i] = (T)a[i]; | |
} | |
return b; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment