Why getClass returns the name of the class + $1 (or $*)

丶灬走出姿态 提交于 2019-11-30 13:37:49

That shows an inner class (either anonymous (if it has a number) or named). For example:

class Foo {
    static class Bar {
    }
}

The name of class Foo.Bar is Foo$Bar. Now if we had:

class Foo {

    static void bar() {
        Runnable r = new Runnable() {
            public void run() {};
        };

        System.out.println(r.getClass());
    }
}

That will print Foo$1.

You can see the same effect in the naming of the class files created by javac.

These are instances of an anonymous class. ViewPart$1 is the first anonymous class defined inside ViewPart - but that doesn't mean it's a subclass of ViewPart. It's most likely an anoymous implementation of some Listener interface.

$ denotes for inner class. For example consider two classes

public class TopClass {
  class SubClass {
     // some methods
  }// inner class end
} // outer class end

If you compile this code you will get two class files TopClass.class and TopClass$SubClass.class.

Check your ViewPart class whether it has any inner classes. Hope it helps.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!