简体   繁体   中英

How to add a parameter to a method inherited by many classes

I am using eclipse and have an interface that is used by many of my classes. Right now, I'd like to add a variable(parameter) to one of the methods in the interface but I don't want to have to go through all of my classes to add the variable manually to each method when I may not even be using that variable in all of those classes.

Is there an easy and quick way to do this without having to do it all manually?

Example:

public interface Screen {
    public void render(GameContainer arg0, Graphics g) throws SlickException;
}

I would like to add the parameter ResourcePack like this:

public interface Screen {
    public void render(GameContainer arg0, Graphics g, ResourcePack pack) throws SlickException;
}

I would like it to add another parameter and have it update all the classes that inherit this method with that parameter so I don't have to do this manually.

Place the cursor on the method and enter : Shift + Alt + C .
You would have a wizard to change the signature of the method (add, remove, edit and order change).
A thing that may be important when you a add a new argument is choosing a default value when it is called.

Here is a simple guide line :

  • If null is an acceptable default value, keep null .
  • If you have a unique way to define the default value from callers, fill this value as needed.
  • If you want to be sure that the value is filled by you, don't let the null value as default value but enter something which doesn't compile in order to be sure that you will have to edit the caller of the method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM