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
반응형

'lang > java' 카테고리의 다른 글

Java System.getenv  (0) 2023.06.08
Java Optional  (0) 2023.06.07
Java Date Offset  (0) 2023.06.07
Java - 2 ArrayList join LinkedHapMap Filter to CSV String  (0) 2022.02.23
java filter speed Test  (0) 2021.12.31