0

I would like to know whether it is possible to verify if a method overload is overridden in an extended class:

class Parent{
    doSomething(int i){
    }
    doSomething(){
    }
}

class Child extends Parent{
    @Override
    doSomething(){
    }
}

Child anInstance = new Child();

if ([doSomething(int i) is overridden in Child]){
    anInstance.doSomething(int i);
}else{
    anInstance.doSomething();
}

I would like to know whether there exists a statement in Java that could be substituted into the square brackets in the code above. If not, what workaround would you suggest?

bkr879
  • 2,035
  • 2
  • 15
  • 23
  • 3
    This smells like bad design. Code shouldn't need to know if a method is overridden or not. – Kayaman Oct 24 '15 at 19:37
  • 1
    Check [How to quickly determine if a method is overridden in Java](http://stackoverflow.com/questions/2315445/how-to-quickly-determine-if-a-method-is-overridden-in-java) – sam Oct 24 '15 at 19:37
  • Are you familiar with Reflection API? – PM 77-1 Oct 24 '15 at 19:38

0 Answers0