Reputation: 691
Generic method :
public <T> void foo(T t);
Desired overridden method :
public void foo(MyType t);
What is the java syntax to achieve this?
Upvotes: 0
Views: 416
Reputation: 1374
A better design is.
interface Generic<T> {
void foo(T t);
}
class Impl implements Generic<MyType> {
@Override
public void foo(MyType t) { }
}
Upvotes: 2
Reputation: 3429
You might want to do something like this :
abstract class Parent {
public abstract <T extends Object> void foo(T t);
}
public class Implementor extends Parent {
@Override
public <MyType> void foo(MyType t) {
}
}
A similar question was answered here as well : Java generic method inheritance and override rules
Upvotes: 2
Reputation: 20542
interface Base {
public <T> void foo(T t);
}
class Derived implements Base {
public <T> void foo(T t){
}
}
Upvotes: 0