jeudi 20 juillet 2017

How to get the original class from anonymous class? Java

I can't figure out how to get the original abstract class or interface where an anonymous inner class is defined.

For example:

public static void main(String[] args) {
    Object obj = new Runnable() {

        @Override
        public void run() {
        }
    };

    System.out.println(obj.getClass());
    System.out.println(obj.getClass().getSuperclass()); //Not what I want
}

Output:

class my.package.MyClass$1
class java.lang.Object

How can I get the original class? (Runnable.class in this case)





Aucun commentaire:

Enregistrer un commentaire