Q:

Confusion with generics on static members of a class

The following code is very confusing to me.
public class Test<T> {
  public static <T> Test<T> ok(T result) {
  ..

I understand the generics in class name. I could understand if "ok" method would be like this
public static Test<T> ok(T result) {

or this
public static T ok(T result) {

But why there is the extra < T > before the Test < T > return type I don't understand.

A:

The example is in fact equivalent to
public class Test<T> {
  public static <U> Test<U> ok(U result) {
  ..

The other <T> refers to a different generic type which applies only to the method. To avoid confusion, it's better to use different names for different things.

