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

  1. arraylist<arraylist<integer>> src
  2. 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

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -