• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

coding problem

 
Ranch Hand
Posts: 41
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
static void call(Integer... i){
System.out.println("hi"+i);
}
static void call(int... i ){
System.out.println("hello"+i);
}
public static void main(String... args){
call(10);
}



can somebody explain why this code does not work?
note: i have omitted the class and main method here!
 
Ranch Hand
Posts: 333
Firefox Browser Windows XP Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Compiler at compile time finds 10 is type of int as well as Integer,hence ambiguity.Compiler should identify that 10 is integer literal not Integer object but unfortunately it happens only at runtime not compile time.
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ankita modi. wrote:Compiler at compile time finds 10 is type of int as well as Integer,hence ambiguity.Compiler should identify that 10 is integer literal not Integer object but unfortunately it happens only at runtime not compile time.



Actually, it is a bit more complex that that -- it has to do with the phases the compiler takes to find an matching method, whether a particular phase finds a matching method or not, and whether a particular phase finds more than one method, in which case, it must resolve the "most specific" one..... and unfortunately, in my opinion, it is in the most unreadable section of the java language specification.... argh!!!

Henry



 
Sahil Manchanda
Ranch Hand
Posts: 41
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

ankita modi. wrote:Compiler at compile time finds 10 is type of int as well as Integer,hence ambiguity.Compiler should identify that 10 is integer literal not Integer object but unfortunately it happens only at runtime not compile time.



Actually, it is a bit more complex that that -- it has to do with the phases the compiler takes to find an matching method, whether a particular phase finds a matching method or not, and whether a particular phase finds more than one method, in which case, it must resolve the "most specific" one..... and unfortunately, in my opinion, it is in the most unreadable section of the java language specification.... argh!!!

Henry





ya mate! sometimes its a Runtime exception but sometimes my compiler gives an error if i am using an IDE
 
I once met a man from Nantucket. He had a tiny ad
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic