Thursday, 29 August 2019

java generic method override

https://stackoverflow.com/questions/41357479/unexpected-bound

above is an example, which doesn't 100% match what i want.


my case is a little bit complex that, i haven generic types in my interface,

and i want to have abstract class which implements above interface. in my abstract class, i would like to change generic types to actual types.


i have explained how to do that in my previous blog post. you can also find here:  https://stackoverflow.com/questions/7433279/is-it-possible-to-have-an-interface-method-defined-with-a-generic-return-type-an


but if your generic type extends another actual type.

public interface SexRule<T, TT extends Timetable> {
public TT getTimeTable();
public String calculateDeadline(T transObj);


}

Note :  Timetable is a interface. SexTimetable  implements Timetable, 


public abstract class ASexRule<OutboundPO, T extends SexTimetable>
implements SexRule <OutboundPO, Timetable> {

public SexTimetable getTimeTable() {
return null;
}

@Override
public String calculateDeadline(OutboundPO po) {
return null;
}

}



you also cannot do : 

public abstract class ASexRule
implements SexRule <OutboundPO, SexTimetable{

public SexTimetable getTimeTable() {
return null;
}

@Override
public String calculateDeadline(OutboundPO po) {
return null;
}

}


No comments:

Post a comment