Covariant return types in interfaces
901800Dec 21 2011 — edited Dec 26 2011Hi,
I was trying this small code snippet to understand covariant returns but when I tried compiling it I get errors saying that I must implement the interfaces. I'm in a bit of a puzzle because I believe that I have implemented them correctly. Can anyone please help me out of this problem....
interface I1 { Number f(); }
interface I2 { Number f(Number i); }
interface I3 { int f(); }
class C {
public Number f() { return 1; }
}
class C2 implements I1, I2 {
public Integer f() { return 1; }
public Integer f(Float i) { return 1; }
}
class C3 extends C implements I2 {
public Float f(Integer i) { return (float) 1; }
}
class C4 extends C implements I3 {
public int f() { return 1; }
}
Any help is greatly appreciated.