As the title states, why can't Java generics be used for static methods?

Asked
Active
Viewed 70 times
1 Answers
5
<T> is the generic type of the class. You cannot refer to it from a static context, since each instance of the class may have a different T (similar to why you can't reference instance members from static methods). You could, however, give the method itself a generic type:
public static <S> S test (S s) {
// code...
}
Mureinik
- 297,002
- 52
- 306
- 350