如何获得必须实现接口的所有方法?

时间:2022-10-30 10:46:46

I am developing a plugin which will create one class with implement interface.The interface may have inherited methods. I also want to implement all the methods including inherited one at the time of creation of the class.Not after the class created and then by using eclipse quick fix--add unimplemented methods. Is there any way to get list of all methods including inherited ones of an interface?

我正在开发一个插件,它将创建一个带有实现接口的类。接口可能有继承的方法。我还想在创建类时实现所有方法,包括继承的方法。在创建类之后不再使用eclipse快速修复 - 添加未实现的方法。有没有办法获得所有方法的列表,包括接口的继承?

4 个解决方案

#1


0  

If you are using Eclipse then eclipse will help you to implement all the required methods which are necessary else you have to see which non implemented method interface has,which you need to implement

如果你正在使用Eclipse,那么eclipse将帮助你实现所有必需的方法,除了你必须看到哪个非实现的方法接口,你需要实现

#2


0  

In your eclipse JAVA editor, you should see an yellow bulb icon with red cross sign(red cross sign is displayed when there are some unimplemented interface methods in the class) in front of the class declaration line. Right click -> quick fix and select the option add unimplemented methods. Eclipse will add stub of all your interface X methods in ClassA body. If there is no red cross sign and your class is getting compiled, it mean, there is no unimplemented method from the class.

在你的eclipse JAVA编辑器中,你应该看到一个带有红色十字标志的黄色灯泡图标(当类中有一些未实现的接口方法时会显示红色十字标志)在类声明行的前面。右键单击 - >快速修复,然后选择添加未实现方法的选项。 Eclipse将在ClassA主体中添加所有接口X方法的存根。如果没有红十字标志并且你的类正在编译,那就意味着,类中没有未实现的方法。

Alternative, you can press ctrl+1 on class A implements X{} line and select the add unimplemented methods option from the menu opened.

或者,您可以在类A上按ctrl + 1实现X {}行,并从打开的菜单中选择添加未实现的方法选项。

Please Note: Hope you have turned on the auto build in Eclipse. If not, please force build to see the compilation error first(red cross sign) in class file open through Java Editor.

请注意:希望您已在Eclipse中打开自动构建。如果没有,请强制构建以通过Java编辑器打开类文件中的编译错误(红叉标志)。

#3


0  

simply when you implemented X in class A then all method which is abstract and not concrete show as a n option when you press Eclipse help short key ctrl+spacebar

当你在A类中实现X时,当你按下Eclipse时,所有抽象而非具体的方法都显示为n选项帮助短按键ctrl + spacebar

#4


0  

Perhaps this example is what you want.

也许这个例子就是你想要的。

package com.interfaces;
import java.lang.reflect.Method;


public class TestImplement  {

    public static void main(String[] args) {    
        Class<?> c = MyInterface.class;     
        Method[] m = c.getMethods();
        for (int i=0; i<m.length ; i++){
            System.out.println(m[i].toString());
        }       
    }
}

interface MyInterface extends Runnable{
    public void test(); 

}

#1


0  

If you are using Eclipse then eclipse will help you to implement all the required methods which are necessary else you have to see which non implemented method interface has,which you need to implement

如果你正在使用Eclipse,那么eclipse将帮助你实现所有必需的方法,除了你必须看到哪个非实现的方法接口,你需要实现

#2


0  

In your eclipse JAVA editor, you should see an yellow bulb icon with red cross sign(red cross sign is displayed when there are some unimplemented interface methods in the class) in front of the class declaration line. Right click -> quick fix and select the option add unimplemented methods. Eclipse will add stub of all your interface X methods in ClassA body. If there is no red cross sign and your class is getting compiled, it mean, there is no unimplemented method from the class.

在你的eclipse JAVA编辑器中,你应该看到一个带有红色十字标志的黄色灯泡图标(当类中有一些未实现的接口方法时会显示红色十字标志)在类声明行的前面。右键单击 - >快速修复,然后选择添加未实现方法的选项。 Eclipse将在ClassA主体中添加所有接口X方法的存根。如果没有红十字标志并且你的类正在编译,那就意味着,类中没有未实现的方法。

Alternative, you can press ctrl+1 on class A implements X{} line and select the add unimplemented methods option from the menu opened.

或者,您可以在类A上按ctrl + 1实现X {}行,并从打开的菜单中选择添加未实现的方法选项。

Please Note: Hope you have turned on the auto build in Eclipse. If not, please force build to see the compilation error first(red cross sign) in class file open through Java Editor.

请注意:希望您已在Eclipse中打开自动构建。如果没有,请强制构建以通过Java编辑器打开类文件中的编译错误(红叉标志)。

#3


0  

simply when you implemented X in class A then all method which is abstract and not concrete show as a n option when you press Eclipse help short key ctrl+spacebar

当你在A类中实现X时,当你按下Eclipse时,所有抽象而非具体的方法都显示为n选项帮助短按键ctrl + spacebar

#4


0  

Perhaps this example is what you want.

也许这个例子就是你想要的。

package com.interfaces;
import java.lang.reflect.Method;


public class TestImplement  {

    public static void main(String[] args) {    
        Class<?> c = MyInterface.class;     
        Method[] m = c.getMethods();
        for (int i=0; i<m.length ; i++){
            System.out.println(m[i].toString());
        }       
    }
}

interface MyInterface extends Runnable{
    public void test(); 

}