Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次の方法が同じである場合、私は混乱していますか?微妙な違いはありますか?
あなたのアドバイスは大歓迎です。
方法 1
public static double sumOfList(List<?> list) {}
方法 2
public static <T> double sumOfList(List<T> list) {}
T メソッド内では、2 番目の case で使用できます。
T
最初のケースではできません。
この例を考えてみましょう
private static <T> void printList(List<T> list) { for (T t: list) { System.out.println(t); }
}
2番目の方法では、次のように使用できます。
T t;
ただし、最初の方法ではできません。その違いだと思います。お役に立てば幸いです。