Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 重写内部类';接口中的方法_Java - Fatal编程技术网

Java 重写内部类';接口中的方法

Java 重写内部类';接口中的方法,java,Java,我有一个接口,在其中我声明了一个内部类: public interface myInterface { int count(); public class myInterfaceInnerClass { public void testOverride() { } } } 类测试实现myInterface: public class Test implements myInterface {

我有一个接口,在其中我声明了一个内部类:

public interface myInterface 
{
    int count();    
    public class myInterfaceInnerClass
    {
        public void testOverride()
        {

        }
    }
}
类测试实现myInterface:

public class Test implements myInterface
{

    public Test() 
    {
        // TODO Auto-generated constructor stub
    }

    public int count()
    {
        return 1;
    }

    //Here I would like to be able to override the inner class' method testOverride
}
是否可以在
类测试中重写内部类的方法
testOverride


编辑:

针对O.Charlesworth的评论,我提出了以下建议:

public interface myInterface 
{
    myInterface aInterface = new myInterfaceInnerClass();
    int count();

    public class myInterfaceInnerClass implements myInterface
    {
        @Override
        public int count() 
        {
            // TODO Auto-generated method stub
            return 0;
        }
        public void testOverride()
        {

        }
    }
}
类测试中

public class Test implements myInterface
{
    public Test() 
    {
        // TODO Auto-generated constructor stub
    }

    public int count()
    {
        return 1;
    }
}
仍然可以重写内部类的方法testOverride吗 这里是
类测试


以下是您可以做的事情:

import myInterface.myInterfaceInnerClass;

public class Test extends myInterfaceInnerClass implements myInterface {

    @Override public int count() {
      // ...
      return 0;
    }

    @Override
    public void testOverride() {
      // ...
    }

}
extend
ing class
myInterfaceInnerClass
的原因(图片>百万字):



(来源:)

这还不清楚<代码>测试
正在实现
myInterface
,它没有扩展
myIntercaceInnerClass
;谈论对未扩展的类的某个方法的过度使用是没有意义的。@OliCharlesworth感谢您的回复。请参见编辑。如果有两个myInterface的实现,myInterfaceInnerClass应该如何运行?@JimmyT。吉米,请你再详细说明一下好吗?谢谢。你为什么要重写这个方法?我不知道为什么会有人想走这条路。只需在接口本身中指定成员即可。@Unheilig我想现在更清楚的是,
扩展myInterfaceInnerClass
适合您的问题。作为旁注,名称
type
s在blockcaseachword中,而不是在camelcaseachword中。语义:)@谢谢你的建议。来自Obj-C世界。:-)@单面体只是想知道,在这种情况下,如果
类测试
已经扩展了某个东西,是否有可能不必
扩展
?谢谢。@Unheilig
类测试
实现
myInterface
,但是
myInterface
不会继承
myInterfaceInnerClass
。等一下,我给你画一幅画。