How to implement unimplemented methods to all child classes in eclipse

前端 未结 3 676
离开以前
离开以前 2021-01-02 06:30

As you know, eclipse provides with a nice way to implement unimplemented methods if a child class does not have them implemented. Is there any way to apply this to all child

相关标签:
3条回答
  • 2021-01-02 06:35

    Problem can be solved using "source/cleanup" feature, after applying few changes in eclipse as:

    1. Make your own project specific profile for Java Code Style/Clean Up:

      Select the Project/BuildPath/Configure Build Path> Click on Java Code Style/Clean Up > Check Enable Project Specific Settings/Edit> Check Add unimplemented methods and give Profile name. enter image description here


    2. Select Project/Source/Clean Up, it will show project name and the profile name we created. Click on finish.
    enter image description here


    Now method will be added to all child classes:
    enter image description here


    Once profile is created, this works even for multiple methods added in the interface or abstract class. Just follow step 2.

    0 讨论(0)
  • 2021-01-02 06:40

    select the top level package in your package explorer. Go to the 'Problems' view. There should be the list of errors of "The type Foo must implement the inherited abstract method Parent.foo()" (for given class/method names). Right click on the error, select "Quick Fix". You can select the "Add unimplemented methods" option and click the "Select All Button" to select all the child classes.

    EDIT: This works even for multiple methods per parent class.

    0 讨论(0)
  • 2021-01-02 06:52

    For Android Studio guys below is the workaround for it, Add this method in your interface or abstract class,

    @Override
            public void methodInInterfaceOrAbstract()
            {
                // this must me in interface or abstract class which will be implemented by child classes 
            }
    

    Then right click the java file, select the option "Refactor" then select the option "Push members down". Select the method which you want to push down to all child classes and click refactor. Your new method added in interface or abstract class will be moved to all child classes. Now you need to add the declaration of the method in interface or abstract class again as the method was moved to all child classes.

    0 讨论(0)
提交回复
热议问题