This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes about the generic method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "about the generic method " Watch "about the generic method " New topic

about the generic method

VuTuan Tran

Joined: Oct 21, 2010
Posts: 14
1.import java.util.*;
2.public class CreateAnArrayList {
3.public <T> void makeArrayList(T t) { // take an object of an unknown type and use a "T" to represent the type
6.List<T> list = new ArrayList<T>(); // now we can create the list using "T";

At line 3. what is the meaning of this public <T> void.I am confusing because unknown type T goes with void in this case.Usually, void is return nothing.
Please help me,thanks
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38020
I presume you are familiar with this Java™ Tutorials section.

Your method creates a List, adds a T to it, then the List disappears when it goes out of scope, and might be garbage-collected. So it doesn't do anything useful.
Don't get me started about those stupid light bulbs.
subject: about the generic method
Similar Threads
public static <T extends Comparable<? super T>> void sort(List<T> list)
Generics doubt
Strange Collections Question from OCP Java SE 6 Programmer Practice Exams book by K & B
Generic question with ?