• Post Reply Bookmark Topic Watch Topic
  • New Topic

Generic methods  RSS feed

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



how can I call the methods, to list and addAll
 
Sheriff
Posts: 21255
87
Chrome Eclipse IDE Java Windows
  • 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.
 
permaculture is giving a gift to your future self. After reading this tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!