Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it bad practice to override a deprecated method?

Is this code bad practice as the method show() is deprecated? Is it okay to override here?

public class Window extends JFrame {

    public Window() {
        // Do things.
    }

    public void show() { // <- Comes up with a warning as deprecated code.
        // Do other things.
    }
}
like image 504
Parzavil Avatar asked Jun 08 '20 14:06

Parzavil


1 Answers

When it's a class that you're extending, it's ideally better to avoid overriding a deprecated method, as in a future release when/if that is removed, and you need to upgrade to the newer version of the library, you will have to rework with the removed method which was deprecated.

If in your instance this is the JFrame class that you're extending, and you intend to override the show() method, you can instead override the setVisible(boolean b) method (doc) which is the replacement for the show() method as mentioned in the javadoc.

Also, it is not advisable to override a base class method and entirely change its function, as

  • You cannot use the method for it's original use-case
  • The method's intent becomes misleading and makes no sense to override the method, when you can actually create a new method which clearly indicates its function
like image 145
Madhu Bhat Avatar answered Sep 29 '22 13:09

Madhu Bhat