Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generic methods

 
vuthlarhi donald
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



how can I call the methods, to list and addAll
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
U is Integer, so:

Although you might want to change one of the wildcards.


public static <U> void addAll(List<U>list, U...array)

You can modify this to have a List<? super U>. That way, you can use a List<Object> as well. Since the list stores U or a superclass of U, it is safe to add the array elements.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic