Why can't I create a new method in an anonymous inner class?

后端 未结 3 937
余生分开走
余生分开走 2021-01-28 10:25

If I have the following class:

public class TestObject {
  public String Hooray() {
    return \"Hooray!\";
  }
}

I can obviously instantiate t

3条回答
  •  温柔的废话
    2021-01-28 11:00

    Because the class has no name, you cannot refer to its type definition at compile time. The compiler can only know it as a TestObject, which has no boo() method

提交回复
热议问题