Question: Suppose the following methods are defined within a generic class
public class<T t> test{...} and all the needed import are there.
Which of the following code snippets compile?
Choice:
A. public static <T, U>void grab(U t) {}
B. public static <T>T self(T t) {return t;}
C. public static <T, U> T process(T t, List<U> s) {return t;}
D. public static <T> T processes(T t, T s) {return t;}
E. public void takes(T t) {}
F. public static <U> void grabs(T t) {}
G.public T check(T t) {return T;}
H. public <U>U checks(U u) {return u;}
Explain: Unless a method is obtaining the generic formal type parameter from the class/interface, it is specified immediately before the return type of the method. D is incorrect because S has no formal type parameter declaration. E is correct because T is declared in the enclosing generic class. F is incorrect because, it declared U as type variable, didn't declare T as type variable, even though T is declared in class level, it can not be used by static method, the compiler error is: non-static type variable T cannot be referenced from a static context. By putting <U, T> before return type void, the static class then declare T as a parameter type for this static method. H is correct because for non-static method, you can declare U as type parameter, despite the fact that it isn't declared in the enclosing class.