10

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 classes?

My problem is that I have to do this for each child class when there are 50 of them. I would appreciate any help.

3
  • I suppose, you still have to implement the semantics of the methods of the 50 sub-classes... So you still have to go to all the classes one-by-one... So why bother with this? It even makes it more difficult, as it is harder to know how far you have gotten... Commented Nov 11, 2011 at 21:33
  • I have a trick to fill those implementation into 50 methods if they exist. So most work of the task is copying the signature stuff into those files. That's why. And I don't understand your last argument as my tests will let me know how far I've gotten. Commented Nov 12, 2011 at 7:21
  • As long as you have not implemented the missing method, the compiler will highlight the missing methods. Which in my book should be faster than finding the missing implementations during testing :-) Good luck with it anyway.... Commented Nov 12, 2011 at 18:59

3 Answers 3

20

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.

Sign up to request clarification or add additional context in comments.

2 Comments

many times, I have pondered on using "abstract" or not because of the trouble it causes (going on each file manually), but I was sure eclipse would help on that! thanks on showing how, no more lazy/carpaltunnel decisions concerning this xD
For Android studio please check the answer @ link stackoverflow.com/questions/8099969/…
3

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.

Comments

2

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.