GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes overloading of method based on return type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "overloading of method based on return type " Watch "overloading of method based on return type " New topic
Author

overloading of method based on return type

firoz silar
Greenhorn

Joined: Dec 24, 2005
Posts: 11
why java does n't support overloading of method based on return type
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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 ]

There is no emoticon for what I am feeling!
karthikeyan Chockalingam
Ranch Hand

Joined: Sep 06, 2003
Posts: 259
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


http://www.skillassert.com


Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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

Joined: Jul 11, 2001
Posts: 14112
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();


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
GeeCON Prague 2014
 
subject: overloading of method based on return type