I noticed that if I use generics on a method signature to accomplish something similar to co-variant return types, it works like I think it would, except it generates a warning:
interface Car {
<T extends Car> T getCar();
}
class MazdaRX8 implements Car {
public MazdaRX8 getCar() { // "Unchecked overriding" warning
return this;
}
}
With the code above, my IDE gives the warning: "Unchecked overriding: return type requires unchecked conversion. Found: 'MazdaRX8', required 'T'"
It makes little sense to me, and Google didn't bring up anything useful. Why doesn't this serve as a warning-free replacement for the following interface (which is also warning free, as co-variant return types are allowed by Java)?
interface Car {
Car getCar();
}