java - Method overload attempt gives name clash error. Not using Generics -
i have following code.
public class myclass { public static void mymethod( arraylist<arraylist<integer>> src, arraylist<arraylist<integer>> dest, integer[] selectedindices) { } public static void mymethod( arraylist<arraylist<double>> src, arraylist<arraylist<double>> dest, integer[] selectedindices) { } }
i expecting overload of mymethod
compiler complains of name clash
error. upon searching so, found related (probably, not sure) answer here, not using generics. methods don't go through type-erasure. can explain missing?
you missing 1 important point here. you still using generics in code.
consider these 2 loc
arraylist<arraylist<integer>> src
arraylist<arraylist<double>> src
java internally, in implementation of these collection classes using generics handle both of these situation , hence face type erasure problem.
edit
just @ arraylist
class
(it @ c:\program files\java\jdk1.7.0_45\src.zip\java\util\arraylist.java)
public class arraylist<e> extends abstractlist<e> implements list<e>, randomaccess, cloneable, java.io.serializable { ... ... public arraylist(collection<? extends e> c) { elementdata = c.toarray(); size = elementdata.length; // c.toarray might (incorrectly) not return object[] (see 6260652) if (elementdata.getclass() != object[].class) elementdata = arrays.copyof(elementdata, size, object[].class); } ... ...
as can see internal structure using generics expected.
Comments
Post a Comment