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 = 

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

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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: