If I have the following:
public interface Foo {
<T extends Foo> T getBlah();
}
public class Bar implements Foo {
public Bar getBlah() {
return this;
}
}
I get a warning in eclipse about the ‘getBlah’ implementation in class Bar:
- Type safety: The return type Bar for getBlah from the type Bar needs unchecked conversion to conform to T from the type
Foo
How can I fix this? And why am I getting the warning?
Thanks
You are overriding a method from your interface, so your implementation you should match the signature from your specification:
Now, if you were instead planning on creating a specifically parametized override of the entire implementation, then you need to specify the generic type as a part of the interface definition: