Annoying Java Bug/Limitation: Generic methods don’t combine well with static imports

package test;
import java.util.*;

import static test.StaticallyImported.*;

public class Test {

  public static void main(String[] args) {

    //passing Type Argument works fine
    HashMap m1 = 
      StaticallyImported.<HashMap>aStaticallyImportedGenericMethod();

    //same thing, with static import syntax: compiler error
    HashMap m2 = <HashMap>aStaticallyImportedGenericMethod();
  }
}

class StaticallyImported {
  static <A extends Map> A aStaticallyImportedGenericMethod() {
    return null;
  }
}
Advertisements