Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

problems in method overloading  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Array{
static void display(float i){
System.out.println("float");
}
public static void main(String[] arg){
long l=400000000000l;
display(l);
}
}

it's output is float.
my problems is why it not showing compilation error .
because i am sending long type (takes 8 byte) as an argument, but in display() method parameter is of float type(take 4 byte).
according to K&B books -:
"when an exact match isn't found, the JVM uses the method with the smallest argument that is wider than the parameter. "
but in this case float(4 byte) is not wider than the long(8 byte).
 
Greenhorn
Posts: 16
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This problem was discussed some days ago in this Thread. There is also a link that seemed to clarify the problem: http://stackoverflow.com/questions/1293819/why-does-java-implicitly-without-cast-convert-a-long-to-a-float
 
Dharmenrda kumar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Thorsten....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!