Skip to content
Advertisement

Tag: type-inference

How is compiler inferring type on a generic method?

I have a Storage class: There are two classes where class Child extends Parent: Parent Child Driver class: Because Storage is a generic class, the operations on its method makes sense; I get how case 1 is working. In case 2, with above signature of max in GenericTest, I get the compilation error: The method max(List<T>) in the type GenericTest

Java generics impossible assignment?

Every time I think I understand generics better (and can answer without compiling), I get to an example where this theory breaks. Here is a very simple example: And two invocations: To me, none of the invocations should compile. A String is not a supertype of List. Still, the second one compiles. But let’s suppose that this happens because the

Advertisement