Question: Suppose the following methods are defined within a generic class
public class<T t> test{...}
Which of the following code snippets compile?
Choice:
A. public static <T>void grab(T t) {}
B. public static <T>T self(T t) {return t;}
C. public static <T, S> T process(T t, S s) {return t;}
D. public static <T> T processes(T t, S s) {return t;}
E. public void takes(T t) {}
F. public static void grabs(T t) {}
G.public T check(T t) {return t;}
H. public <T>T checks(T t) {return t;}
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 non-static type variable T cannot be referenced from a static context. By putting <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 T as type parameter again, despite the fact that it has already being declared in the enclosing class.