The Artima Developer Community
Sponsored Link

Java Answers Forum
Polymorphism vs Methods Signatures Best Fitness

2 replies on 1 page. Most recent reply: Jul 13, 2005 12:36 PM by Antonio

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Antonio

Posts: 33
Nickname: arhak
Registered: Jul, 2005

Polymorphism vs Methods Signatures Best Fitness Posted: Jul 13, 2005 12:31 AM
Reply to this message Reply
Advertisement
Say we have two methods

void f(Object obj, String str) { System.out.println("obj - str"); }

and
viod f(String str, Object obj) { System.out.println("str - obj"); }


what should happend when you invoke
f("a", "b")
?

Do you think the compiler should warn us about it?
How (and Why) the compiler choose?


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Polymorphism vs Methods Signatures Best Fitness Posted: Jul 13, 2005 5:24 AM
Reply to this message Reply
Are you sure that would even get compilation
Stage?

Have you tried it?

Would it not complain about applying
f(java.lang.String, java.lang.String) to f(java.lang.Object,java.lang.String)?

Haven't tried it but I've come across similar
scenarios.

Antonio

Posts: 33
Nickname: arhak
Registered: Jul, 2005

Re: Polymorphism vs Methods Signatures Best Fitness Posted: Jul 13, 2005 12:36 PM
Reply to this message Reply
Well, I have that doubt since JDK 1.2 or 1.3 maybe, when I tried and it did compile. But now you say so, I try again and it's fixed. It doesn't compile.

reference to f is ambiguous; both method f(java.lang.Object, java.lang.String) in ... and method f(java.lang.String, java.lang.Object) in ... match at ...


It's curious I haven't try with JDK 1.4 nor 1.5

Flat View: This topic has 2 replies on 1 page
Topic: Passing arguments to a single file in netbeans Previous Topic   Next Topic Topic: HELP migrating from 1.4.2 to 1.5.0 netbeans 3.6

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use