I know how to workaround this problem, but still looking for knowledge of concept why the below problem arises.
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
public class TypeTest {
class TypedClass<TYPEA, TYPEB> {
private Integer value = 1;
public List<Integer> getValueAsList() {
return Arrays.asList(value);
}
}
@Test
public void testType() {
TypedClass typedClassWithOutTypeInfo = new TypedClass();
TypedClass<?,?> typedClassWithTypeInfo = new TypedClass();
System.out.println(typedClassWithOutTypeInfo.getValueAsList().stream().findFirst().get().intValue()); //ERROR. get() returns Object rather than Integer
System.out.println(typedClassWithTypeInfo.getValueAsList().stream().findFirst().get().intValue()); //Works.
}
}
NutShell: Even though the method returnType does not depend on classType, it's lost if class is declared without typeInfo.