File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overloading of method based on return type

 
firoz silar
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why java does n't support overloading of method based on return type
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It can lead to ambiguities that can't be resolved. In the code above g overloads based on return type. In method test you could be using either version of g -- it can't be determined.
[ January 19, 2006: Message edited by: Jeff Albrechtsen ]
 
karthikeyan Chockalingam
Ranch Hand
Posts: 259
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Jdk 1.5 or Tiger version , covariant return types are allowed.
For more information http://java.sun.com/developer/JDCTechTips/2004/tt1201.html#2
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by karthi keyan:
In Jdk 1.5 or Tiger version , covariant return types are allowed.
For more information http://java.sun.com/developer/JDCTechTips/2004/tt1201.html#2


Note that covariant return types are part of overriding, not overloading.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeff Albrechtsen:
It can lead to ambiguities that can't be resolved. In the code above g overloads based on return type. In method test you could be using either version of g -- it can't be determined.



In fact you are allowed to ignore the return value, in which case it already would be ambigious:

g();
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic