This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Generic methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Generic methods" Watch "Generic methods" New topic
Author

Generic methods

vuthlarhi donald
Ranch Hand

Joined: Jul 31, 2006
Posts: 76



how can I call the methods, to list and addAll
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
wood burning stoves
 
subject: Generic methods
 
Similar Threads
Subdividing a Collection into smaller collections
Boxing with Arrays.asList()
add(index,object) and reverseOrder()
Observing non Observable
Generics and a copy method