Menu

#51 Better compiler warnings for ambiguous methods

open
nobody
None
5
2007-01-07
2007-01-07
No

Currently it's very easy to create ambiguous methods without being warned about it. Some examples:

class Foo { }
class Bar extends Foo { }

// Compiles without a twitch.
void doStuff(Foo foo1, Foo foo2) { }
void doStuff(Foo foo1, Bar foo2) { }
void doStuff(Bar foo1, Foo foo2) { }

// Doesn't compile
doStuff(new Bar(), new Bar());

Another example which the compiler doesn't catch (and is probably never intentional):

let String foo = "foo";

public void doStuff(String string) { }

doStuff(foo) { System.out.println("Hi!"); }
doStuff("foo") { System.out.println("Bye!"); }

Ambiguous methods aren't neccessarily a problem and presumably can be deliberate in some cases, so this probably shouldn't be considered an error. It would however be very useful if the compiler could warn when you've done this.

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.