Skip to content

Instantly share code, notes, and snippets.

@czxttkl
Created October 15, 2014 14:38
Show Gist options
  • Save czxttkl/020573f2525fcbeae522 to your computer and use it in GitHub Desktop.
Save czxttkl/020573f2525fcbeae522 to your computer and use it in GitHub Desktop.
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