• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

overloading of method based on return type

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why java does n't support overloading of method based on return type
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic