[英]How can I create a subclass of an abstract class automatically in Eclipse in Java?
say I had an abstract java class in eclipse. 说我在Eclipse中有一个抽象的Java类。 Now I want to create some subclasses of that abstract class.
现在,我想创建该抽象类的一些子类。 Is there a way to create them automatically where I just enter the name of the class and eclipse creates the necessary methods?
有什么方法可以自动创建它们,只要我输入类的名称,然后eclipse即可创建必要的方法?
I thought that I would find it in the "Refactor" option but I didn't. 我以为可以在“重构”选项中找到它,但没有找到。 Can someone help me?
有人能帮我吗?
Yes, create a new class using Right Click (on the package where you want to create the class) > New > Class , and in the SuperClass field, you can select your abstract
class. 是的,使用右键单击 (在要创建类的包上)创建一个新类> New > Class ,然后在SuperClass字段中选择
abstract
类。 Be sure that the checkbox Which method stubs would you like to > Inherited abstract methods is checked. 确保已选中您想要的方法存根复选框> 继承的抽象方法 。
If you have already created your class, you can make it extend you abstract
class by hand, and use Right Click (on the source code) > Source > Override/Implement Methods... and choose which methods you want to implement (if they are not already implemented). 如果已经创建了类,则可以使其手动扩展
abstract
类,并使用右键单击 (在源代码上)> Source > Override / Implement Methods ...,然后选择要实现的方法(如果它们尚未实施)。
An other way to do it, is to extend your abstract
class by hand, and use the Quick Fix provided by Eclipse to Add unimplemented methods . 另一种方法是手动扩展您的
abstract
类,并使用Eclipse提供的快速修复来添加未实现的方法 。 You can call the Quick Fix tooltip by highlighting the error and using Ctrl+1 , or by clicking on the error icon on the left of the code. 您可以通过突出显示错误并使用Ctrl + 1或单击代码左侧的错误图标来调用快速修复工具提示。
Use the New Class
as normal but then specify your abstract class as the Superclass
. 照常使用
New Class
,然后将抽象类指定为Superclass
。 Then check Which methods stubs would you like to create
-> inherited abstract methods
然后检查
Which methods stubs would you like to create
-> inherited abstract methods
只需创建一个扩展抽象类的类,默认情况下eclipse将添加所有未实现的方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.