How can I call a Generic method with a type, when it's statically imported?

You can't. You'd have to reference it using the class name.

It seems that having:

void foo(List<String> a) {}

and calling foo(createList()) does not infer the correct type. So you should either explicitly use the class name, like ListUtils.createList() or use an intermediate variable:

List<String> fooList = createList();
foo(fooList);

Finally, guava has Lists.newArrayList(), so you'd better reuse that.


The following works for me:

package test;
import java.util.List;
import static test.ListUtils.createList;

public class ListConsumer {
    public static void main(String[] args) {
        List<Integer> list = createList();
        List<String> list2 = createList();
    }
}

You can't. This is a design flaw in the syntax of the Java language. Scala, which is a newer statically typed language on JVM, fixes this. (This is how you'd make that call in Scala: val intList: List[Int] = creatList[Int]()).