Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Covariant return types in interfaces

901800Dec 21 2011 — edited Dec 26 2011
Hi,
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.
This post has been answered by EJP on Dec 21 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 23 2012
Added on Dec 21 2011
14 comments
301 views