I got into a situation perfectly described in this post(one of the answers) in: is it possible to overload a final method
My question is if there is a way to execute the Derived class method, or another way... It would help a lot in my project to avoid duplicated code just for casting and doing the same operations inside the methods(which are many).
My concern is just to keep the code in one location for maintenance and debugging, and I cant find a way by myself. Thanks in advance.
class Base { public final doSomething(Object o) { System.out.println("Object"); } } class Derived extends Base { public doSomething(Integer i) { System.out.println("Int"); } } public static void main(String[] args) { Base b = new Base(); Base d = new Derived(); b.doSomething(new Integer(0)); d.doSomething(new Integer(0)); }
final? It sounds like you want to be able to override it . . .