【问题标题】:Implement interface declared in innerclass实现内部类中声明的接口
【发布时间】:2012-02-04 09:35:35
【问题描述】:

这是一个 Java 问题 如何在外部类中实现内部类的接口?

我尝试了以下方法,但徒劳无功。谢谢你

class A implements interface B.C{
   static class B{
        interface C{

        }
   }
}

【问题讨论】:

  • 也许是implements A.B.C。但为什么呢?
  • 但 eclipse return 不能扩展/实现自身或它自己的成员类型之一

标签: java interface inner-classes


【解决方案1】:

我会这样做:
假设这两个类都在同一个包中,并且有正确的导入。

public class Nestedinterface {
     public interface NestI{
         void show();
     }
}

public class NestedinterfaceImpl implements NestI {
    public static void main(String a[]) {
        NestI n = new NestedinterfaceImpl();
        n.show();
    }
    public void show() {
        // TODO Auto-generated method stub
        System.out.println("Hello world");    
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-26
    • 2013-11-13
    • 1970-01-01
    • 2019-01-05
    • 2018-05-12
    • 2021-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多