简体   繁体   English

如何在Java的Eclipse中自动创建抽象类的子类?

[英]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.

相关问题 如何创建and抽象类的数组,以便可以将其初始化为特定的非抽象类(java) - How can I create an array of and Abstract class such that I can initialize it to a specific non-abstract class (java) 创建子类对象时如何调用抽象类构造函数? - how is it call abstract class constructor when i create subclass object? 在 Java 中,我可以在变量中存储 class 类型吗,其中 class 是抽象 ZA2F2ED4F18EBC2B61DZC2 的某个子类? - In Java, can I store a class type in variable, where the class is some subclass of an abstract class? 抽象类的子类的Java构造函数 - Java constructor of a subclass of an abstract class 我无法创建 eclipse java 类 - I can`t create an eclipse java class 如何从另一个类的静态方法获取抽象类的子类的实例? - How can I get an instance of a subclass of abstract class from a static method of another class? 如何访问从Java中抽象类的子类实例化的对象? - How do I access the object that's been instantiated from the abstract class's subclass in java? 我可以将对象从子类传递到抽象类吗? - Can I pass object from subclass to abstract class? 如何在Eclipse外的项目中使用java Eclipse Abstract Syntax Tree? (即不是eclipse插件) - How can I use the java Eclipse Abstract Syntax Tree in a project outside Eclipse? (ie not an eclipse plugin) Java:如何在抽象类中引用子类的静态变量? - Java: How to refer to subclass's static variable in abstract class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM