- What do
T
andS
mean? public void main(String... abc)
; what does...
mean? Is...
called generic as well?
views:
184answers:
5
+9
A:
- That are parameterized types. You can use any identifier here to represent a certain object type.
- That are varargs. You can pass a single String, or multiple Strings, or a String array in.
BalusC
2009-12-10 02:36:19
+1
A:
- 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.
- That indicates that the method can accept a variable number of arguments. See varargs. It's basically sugar around an array.
Hank Gay
2009-12-10 02:36:45
+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
2009-12-10 02:37:41
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
2009-12-10 02:42:06
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
2009-12-10 02:52:02
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
2009-12-10 14:48:50
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:
Jakob Jenkov
2009-12-10 18:21:10