tags:

views:

184

answers:

5
  1. What do T and S mean?
  2. public void main(String... abc) ; what does ... mean? Is ... called generic as well?
+9  A: 
  1. That are parameterized types. You can use any identifier here to represent a certain object type.
  2. That are varargs. You can pass a single String, or multiple Strings, or a String array in.
BalusC
+1  A: 
  1. Please read the documentation. Briefly, they are type parameters so that generic types and methods can know what type of objects they are acting on.
  2. That indicates that the method can accept a variable number of arguments. See varargs. It's basically sugar around an array.
Hank Gay
+3  A: 

T and S are generic classes. They can be any type of class that you want. For example, Map<K, V> uses the K for the key class and V for the value class.

Map<Integer, String> map = new HashMap<Integer, String>

As for the String..., it means any number of String parameters.

Kaleb Brasee
1.can i use any other alphabet , A,B,C,Z ? rather than T,S,K,V ?2. is Map(K,V) same as Map(S,T) ? can use any alphabet?
cometta
You can use any identifier you want as long as it does't clash with existing classnames in the classpath. The normal coding convention is indeed a single uppercased character (because it is not normal to have a class with only one character as name).
BalusC
A: 

complementing: String... is almost the same as String[].
On the method side it is the same,
on the calling side the're is a difference: the compiler creates the array from the parameters.

void method(String... args) {
    // args is an array: getClass() returns [java.lang.String
    if (args.length >  0) {
        System.out.println(args[0]);
...
    method();               // same as method(new String[0]);
    method("1", "2", "3");  // same as method(new String[] {"1", "2", "3"});
Carlos Heuberger
A: 

Sun's Java Generics documentation can be a bit hard to understand at times, so I tried to write a simpler tutorial on Java Generics. You can find it here:

http://tutorials.jenkov.com/java-generics/index.html

Jakob Jenkov