Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What approach to use in own programs to leverage updates to future java versions?

If a developer extends a Java class that is part of the JDK and adds new methods to it, there is always the risk that a future version of java may introduce methods with the same name/signature resulting in unwanted behaviour if the program is executed with these future versions. Since there is no "Non-Overrides" annotation available (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7152222) which would detect such possible problems when someone compiles the code with a newer version of the JDK, the developer has to do this checks in a different way. Which approach do you use?

like image 541
mschenk74 Avatar asked Apr 29 '13 11:04

mschenk74


1 Answers

It is an antipattern to extend JDK's classes, except those that are specifically designed to be used by extending them. You should use the Decorator pattern instead to add features to JDK classes. JDK is no special case, either, this holds for any 3rd party libraries as well.

like image 84
Marko Topolnik Avatar answered Sep 22 '22 05:09

Marko Topolnik