Java Compilation Error with Method overloading -


what best way achieve testcall2 below without doing explicit parsing (sub1) in?

class super { }  class sub1 extends super { }  class sub2 extends super { }  public void testcall2(super in) {     testcall(in);        // <~~~ compilation error   }  public void testcall(sub1 sub) {  }  public void testcall(sub2 sub) {  } 

you'd have refactor , use polymorphism. declare testcall method in super

class super {     public void testcall() {} } 

and implement in subclasses.

then invoke it

public void testcall2(super in) {     in.testcall();  } 

otherwise you'll have use cast transform value's type type expected either of methods.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -