generics - implementation with different signature java -


while developing architecture of classes meet need, have confronted case. have abstract class has methods inside must implemented subclass, in subclass discovered needed implement signature inherits first on.

to show mean:

// person class public abstract class person {    protected void abstract workwith(object o) throws exception; }  //developer class public class developer extends person {// want implement method computer parametre instead of object , throws `//developerexception instead of exception`  protected void workwith(computer o) throws developerexception  {   //some code here lol install linux ide server , stuff   } }  // exception class  public class developerexception extends exception {  } 

is there way it? not know if possible generic. thank much.

you can use generics this:

public abstract class person<t, u extends exception> {    protected abstract void workwith(t t) throws u; }  class developer extends person<computer, developerexception> {   protected void workwith(computer c) throws developerexception {     //implementation code   } } 

this accomplishes want, need lot more details regarding use case determine whether right design use.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -