Heru Salim

Greenhorn
+ Follow
since Mar 27, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Heru Salim

Originally posted by Srinivasan thoyyeti:
Hi Heru,

I got you in the first mail in your first mail.
Considering Prasad Example here.



Here pay attention to where the Raptor Instance stored? (which is NewBird reference "rap")
NewBird reference rap can only call methods defined in itself. "rap" can't call Raptor class's method, though "rap" pointing to Raptor Object, unless until any method overriding done in Raptor.

Hope its clear now.



Ah ha...
Now i get it. It just like rap has no interface to access doSomething(int), so it calls doSomething(int, int...) instead, which match to the calls rap.doSomething(1).

Thanks for the explanation.

Heru
Hi Keith,

just guessing, that you didn't try the code from Prasad, did you?
That was also my guess, that Raptor.doSomething(int) preceed NewBird.doSomething(int, int...), when it's called by



That's why I was also surprised and guessed that signature method(int, int...) has a higher priority than method(int) when called with method(1).

It is also new for me, and have no idea about the real reason.

Heru

Originally posted by Keith Lynn:
No, it doesn't have a higher priority.

The reason that doSomething(int,int...) is called when the method invocation is doSomething(int) is that it matches the call.

doSomething(double,int) does not match doSomething(int)



Maybe I misunderstood.
But I didn't compare NewBird.doSomething(int, int...) with NewBird.doSomething(double, int). I compared instead NewBird.doSomething(int, int...) with Raptor.doSomething(int), which both could represent the calls of rap.doSomething(1).

As an example if I change the signature of NewBird.doSomething(int, int...) into NewBird.doSomething(int), the Raptor.doSomething(int) will be called, when it's called via rap.doSomething(1).

Hope that my explanation about my opinion could be understood.

Heru
Hi Prasad, Dont you see another thing that is happening with your code.
You passed two int's and the doSomething(double,int) is called instead of
doSomething(int,int...);

Preference is given to (double,int) version of doSomething() instead of var argument one.
"Preference is given to widening (int to double) instead of var arg"

Regards,
cmbhatt

[ March 27, 2007: Message edited by: Chandra Bhatt ][/QB]

Hi,

I don't think it's not the only the cause. It only explain the second call "doSomething(1,2)", but doesn't explain the call of "doSomething(1)".

I thought previously that the output should be "CiaoOla" (regarding to polymorphism concept), but I was wrong.

I think the problem is that "doSomething(int, int...)" has a higher priority than "doSomething(int)", when it's called "doSomething(1)".

Don't know exactly about that, but I think that's the reason I found out.

Regards,
Heru