java - Parameterized Lists in method signature -
java - Parameterized Lists in method signature -
something next not give me compile-time or runtime error , i'm drawing blank why. there way enforce compile error on phone call cls.add?
why isn't definition of t in class definition beingness carried on phone call methods inside? understand didn't instantiate class way, definition of class states t must number.
public class newclass<t extends number> { private list<t> id = new arraylist<t>(); public void add(list<t> elem) { id.addall(elem); } public static void main(string[] args) { newclass cls = new newclass(); cls.add(new arraylist<string>()); } }
you using raw type. type info ignored in case, , warning.
if provide type parameter, fail:
newclass<integer> cls = new newclass<integer>(); cls.add(new arraylist<string>()); //error
java generics
Comments
Post a Comment