Calling static common methods

I came across a curious situation involving static general 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(); } } 

Why don't I need to specify any type arguments in a Foo.createFoo() expression? Is this some kind of output? If I want to be explicit, how do I specify a type argument?

+80
java generics static type-inference
Mar 14 '11 at 11:32
source share
1 answer

Yes, this is type inference based on the purpose of the destination, according to the JLS section 15.12.2.8 . To be explicit, you would call something like:

 Foo.<String>createFoo(); 
+124
Mar 14 2018-11-11T00:
source share



All Articles