I thought I would already understand Java generics. But now I'm helpless again.
I have a generic class where c-tor builds a properly typed instance, while the static factory method creates a type mismatch.
Take a look at the following code:
public class _GenericFactoryMethods { public final static class DemoClass<T1, T2> { private final T1 _1; private final T2 _2;
Error:
Uncompilable source code - incompatible types required: _GenericFactoryMethods.DemoClass<java.lang.Class<? extends java.lang.CharSequence>,java.lang.CharSequence> found: _GenericFactoryMethods.DemoClass<java.lang.Class<capture#794 of ? extends java.lang.CharSequence>,java.lang.CharSequence>
Please help to understand and solve this.
(I really need static factory methods for some of these classes).
EDIT
Can someone else explain why explicit type parameters should be used
source share