Reputation: 4487
I want to check String
is interface or not using Reflection
method .isInterface
. Here is what I tried but it gives Class not found exception.
public class CheckingClassType {
public static void main(String args[]) {
try {
Class c = Class.forName("String");
System.out.println(c.isInterface());
} catch (Exception e) {
System.out.println(e);
}
}
}
Upvotes: 0
Views: 44
Reputation: 5786
Use Class c = Class.forName("java.lang.String");
You need to give the full package name of the class. The reflection needs to know that to instantiate the class name as multiple classes with same name can exist in different packages.
Upvotes: 3