0

I am new to java.I was going through a tutorial on java generics.

Java Generics tutorial There is a section about declaring generic methods and constructors.

Methods and constructors can be generic if they declare one/more type variables.

public static <T>T getFirst (List<T> list)

This method accepts a reference to List and will return an object of type T.

why is there a T after static? Is this a printing mistake.?

What does that mean?

I am a beginner in java an new to the concepts of generics.

4

2 に答える 2

4

メソッド名のT前の は、 type の値を返すことを意味しますT。ここで、T はメソッドで使用されるテンプレートです。メソッドが を返す場合、次のintようになります。

public static <T> int getFirst (List<T> list)
于 2013-07-25T05:00:35.153 に答える
2

T の型パラメーターを意味しjava.lang.Class、この型パラメーターを追加しました。これは単に、コンパイラーへの型チェックを意味します。

于 2013-07-25T05:09:07.110 に答える