简体   繁体   English

在Java中“匿名类仅实现接口或扩展类而不同时扩展类”的原因是什么?

[英]what is the reason for “Anonymous class only implement the interface or extend the class but not both” in java?

I have read Anonymous class can only implement the interface or extend the class but not both. 我读过匿名类只能实现接口或扩展类,但不能同时实现。 But I don't know what is the key reason behind it to prevent both at the same time? 但是我不知道同时阻止两者的主要原因是什么?

Please enlighten me on this... 请给我启发...

Because anonymous class basically doesnt has any name. 因为匿名类基本上没有任何名称。 So you basically cannot write 所以你基本上不能写

Class someClass extends SomeOtherClass implements SomeInterface

you do it like 你喜欢

new SomeClass/SomeInterface(){
  @override
  public void someMethod(){
  }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM