lang/java
Java isInstance
C/H
2023. 6. 8. 08:57
package org.example.reflect;
import java.util.Enumeration;
import java.util.Properties;
class A {}
public class isInstance {
public static void main(String[] args) {
try {
Class klass = Class.forName(isInstance.class.getPackage().getName() + ".A");
Boolean isInstance1 = klass.isInstance(new Integer(37));
System.out.println("isInstance1 isInstance klass: " + isInstance1);
Boolean isInstance2 = klass.isInstance(new A());
System.out.println("isInstance2 isInstance klass: " + isInstance2);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
> Task :isInstance.main()
isInstance1 isInstance klass: false
isInstance2 isInstance klass: true
반응형