This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Covariant Return Types

 
Jerry Ragland
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Programmer {
Programmer debug() {return this;}
}

class SCJP extends Programmer {
Object debug() {return this;}
}

why the compilation fails saying in compatible return type during an override?
All class extends Object so SCJP IS-A Object and hence return this; should be accepted as a covariant return type ... Correct???

Some one please explain....

Thanks,
Jerry Ragland.
 
Remko Strating
Ranch Hand
Posts: 893
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Object is a supertype of Programmer and not a subtype

Covariant Return types only applies to the subtypes of the overriding return type. In this case Programmer and al subclasses of Programmer.
 
Jerry Ragland
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the clarification.. Got it...

-Jerry.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic