overloading - Java method overload - ambiguity -


while doing runs test code in thread found out strange thing, if consider following program

import java.util.arraylist; import java.util.list;  public class overloadtest {      public string test1(list l){         return "abc";     }      public int test1(list<integer> l){         return 1;     }      public static void main(string [] args) {         list l = new arraylist();         system.out.println(new overloadtest().test1(l));     } } 

i expecting java compiler show ambiguity error due byte-code erasure property, didn't. when tried run code, expecting test1(list) called , output "abc" surprise called test1(list<integer>) (output 1)

i tried below

list l = new arraylist(); l.add("a"); system.out.println(new overloadtest().test1(l)); 

but still found java calling test1(list<integer> param) method , when inspected param had string "a" ( how did java cast list<string> list<integer> ?)

this fixed bug. https://bugs.eclipse.org/bugs/show_bug.cgi?id=354229

it looks bug existed in javac5, javac6 , ecj eclipse 3.7, fixed in eclipse 3.8 , later.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -