Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

covariant returns

 
Satish Ray
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody explain me what exactly are covariant returns?
 
Petrus Pelser
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Covariant returns are when you return a subtype of the return type defined by the method you are overridding.

E.g


This is a legal override as the overridden method returns a subtype of the original method's return type.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note also that covariant returns are legal in JDK 5 and later, but not in earlier versions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic