osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

InvalidTypesException: Type of TypeVariable 'K' in 'class X' could not be determined


Hello,

I have some code which compiles correctly (Flink 1.4) under Java 8.
It uses generic types.
While it compiles correctly, the execution fails with the error:

org.apache.flink.api.common.functions.InvalidTypesException: Type of TypeVariable 'K' in 'class X' could not be determined.

This is my main:

public static void main(final String[] args) {
X<Long> x = new X();
}

This is my class X:

public class X<K> {
    public X() {
TypeInformation<K> keySelector = TypeInformation.of(new TypeHint<K>(){});
}
}


Perhaps I'm lacking knowledge on the way Java's generics work, but why can't Flink determine the TypeVariable of 'K'?
As I am instantiating X parameterized as a Long, that information should eventually reach Flink and the constructor of X would be equivalent to this:

public X() {
TypeInformation<Long> keySelector = TypeInformation.of(new TypeHint<Long>(){});
}
During execution, however, this error pops up.
What am I missing here, and what is the best way to achieve this generic behavior in a Flink-idiomatic way?

Thank you very much for your time.