This question already has an answer here:
I've got an array of any class and I need to get that class at runntime.
I'm thinking of something like that:
String[] stringArray = new String[10];
Class<?> clazz = stringArray.getClass();
if (String.class.isAssignableFrom(clazz)) {
System.out.println("Won't happen");
}
The class of the array is not known at compile time.
I've found something simular but the other way here (String.class --> String[].class)
Aucun commentaire:
Enregistrer un commentaire