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
Post a Comment