Created
August 20, 2013 19:03
-
-
Save dushmis/6285763 to your computer and use it in GitHub Desktop.
Create an array using Java reflection api
This file contains hidden or 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
try { | |
Class cls = Class.forName("java.lang.String"); | |
Object arr = Array.newInstance(cls, 10); | |
Array.set(arr, 5, "test string.."); | |
String s = (String)Array.get(arr, 5); | |
System.out.println(s); | |
}catch (Throwable e) { | |
System.err.println(e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment