Why do i get a compilation error on eclipse with the following definition in an interface:
Area is an interface.
public interface Shape {
...
public Comparator<T extends Area> getComparator();
}
and not if I use instead:
public interface Shape {
...
public Comparator<? extends Area> getComparator();
}
Because the compiler has no idea what T is supposed to be or represent. Now, if you had something like public interface Shape<T> as the interface declaration, we could probably get something to work with that.
T isn't defined in the code sample you've shown.
The following should be legal:
public interface Shape {
...
public <T extends Area> Comparator<T> getComparator();
}
or:
public interface Shape<T extends Area> {
...
public Comparator<T> getComparator();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With