File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Explain about most specific code and this example Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply locked New topic
Author

Explain about most specific code and this example

vvus bharadwaj
Ranch Hand

Joined: Apr 28, 2012
Posts: 38
I studied the most specific method tutorial.I understand that when there are two or more applicable methods are there then the compiler will choose the specific method.That method can be chosen by comparing the applicable method arguments.The method1 arguments that are valid for (i.e they can be assigned to)method2 arguments but not vice versa then method1 is most specific.In the first example i posted method1 arguments(int) can be easily assigned to method arguments(Integer) and method2(Integer) arguments are also easily assigned to method1(int). So compiler cannot determine the specific method.
This is the first example.
class Boxing2
{
public static void main(String args[])
{
dostuff(4);
}
static void dostuff(int... z) //method1
{
System.out.println("int");
}
static void dostuff(Integer... z) //method2
{
System.out.println("Integer");
}
}
I understood this much concept from what i have studied.Is this right?Then i have another doubt regarding the below example?
class Boxing2
{
public static void main(String args[])
{
dostuff(4);
}
static void dostuff(long... z) //method1
{
System.out.println("int");
}
static void dostuff(Integer... z) //method2
{
System.out.println("Integer");
}
}
In this example method1 arguments(long) cannot be assigned to method2 arguments(Integer) but method2 arguments(Integer) can be assigned to method1 arguments(long).So method2 is most specific methos.Why compiler cannot determine this one and showing an error that is same error as in first example?
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 867

Please don't create duplicate threads. there is already thread going on over here http://www.coderanch.com/t/584352/java-programmer-SCJP/certification/Explain-code. wait for other ranchers to answer your question. please read http://www.coderanch.com/how-to/java/PatienceIsAVirtue


OCPJP 6(100 %) OCEWCD 6(91 %)
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

So, Locking this thread.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Explain about most specific code and this example
 
Similar Threads
need help in overloading...
Explain this code?
Wrapper throws NullPointerException, how to correct code
Wrappers
Query on Wrapper