I have come across a curious situation involving static generic methods. This is the code:
class Foo<E>
{
public static <E> Foo<E> createFoo()
{
// ...
}
}
class Bar<E>
{
private Foo<E> member;
public Bar()
{
member = Foo.createFoo();
}
}
How come I don't have to specify any type arguments in the expression Foo.createFoo()
? Is this some kind of type inference? If I want to be explicit about it, how can I specify the type argument?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…