-2

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

0

1 Answer 1

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... } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.