Friday, August 03, 2007

Array: new vs. java.lang.reflect.Array.newInstance

Since i was writing about array I thought this is also worth mentioning.
There are two ways of creating array
String str[] = new String[4];
String str[] = (String[]) java.lang.reflect.Array.newInstance(String, 4);

Both are same, you use second one where you can't use the first i.e. you don't know the type of array in advance.

No comments: