Generics 自定义泛型类的Flink类型提取问题

Generics 自定义泛型类的Flink类型提取问题,generics,apache-flink,type-erasure,Generics,Apache Flink,Type Erasure,(弗林克1.3) 我在类型提取方面有问题: The return type of function '...' could not be determined automatically, due to type erasure. You can give type information hints by using the returns(...) method on the result of the transformation call, or by letting your f

(弗林克1.3)

我在类型提取方面有问题:

The return type of function '...' could not be determined 
automatically, due to type erasure. You can give type information hints 
by using the returns(...) method on the result of the transformation 
call, or by letting your function implement the 'ResultTypeQueryable' 
interface.
使用
数据流时
其中:

public class MyGenericClass<T> extends Tuple2<String, T> {
    ...
}
公共类MyGenericClass扩展了Tuple2{
...
}
如果没有
.returns(..)
解决方案,我如何解决问题?
您能给我一个关于如何实现类型信息工厂或如何为
MyGenericClass
实现
ResultTypeQueryable
的示例吗

提前感谢您

免责声明:我的回答基于您使用Java8 lambda表达式的假设

我不是很确定,但根据Flink文档,这是一个问题,因为诸如OpenJDK和Oracle JDK的javac之类的编译器丢弃了所有与Lambda表达式相关的通用参数。这意味着声明为Lambda函数输入或输出参数的Tuple2或Collector等类型将在编译的.class文件中修剪为Tuple2或Collector,这对于Flink编译器来说太少了。”

根据相同的Fink文档——“只有EclipseJDT编译器保留了安全使用整个Lambda表达式功能类型所需的泛型类型信息。”

所以,为了解决这个问题,您可以在pom.xml中手动添加以下信息,以便您的maven使用Eclipse JDT编译器-

<!-- put these lines under "project/build/pluginManagement/plugins" of your pom.xml -->

<plugin>
  <!-- Use compiler plugin with tycho as the adapter to the JDT compiler. -->
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <source>1.8</source>
    <target>1.8</target>
    <compilerId>jdt</compilerId>
  </configuration>
  <dependencies>
    <!-- This dependency provides the implementation of compiler "jdt": -->
    <dependency>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-compiler-jdt</artifactId>
        <version>0.21.0</version>
    </dependency>
  </dependencies>
</plugin>

免责声明:我的回答基于您使用Java8 lambda表达式的假设

我不是很确定,但根据Flink文档,这是一个问题,因为“OpenJDK和Oracle JDK的javac等编译器丢弃了所有与Lambda表达式相关的通用参数。这意味着声明为Lambda函数输入或输出参数的Tuple2或Collector等类型将在编译的.class文件中修剪为Tuple2或Collector,这对于Flink编译器来说太少了。”

根据相同的Fink文档——“只有EclipseJDT编译器保留了安全使用整个Lambda表达式功能类型所需的泛型类型信息。”

所以,为了解决这个问题,您可以在pom.xml中手动添加以下信息,以便您的maven使用Eclipse JDT编译器-

<!-- put these lines under "project/build/pluginManagement/plugins" of your pom.xml -->

<plugin>
  <!-- Use compiler plugin with tycho as the adapter to the JDT compiler. -->
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <source>1.8</source>
    <target>1.8</target>
    <compilerId>jdt</compilerId>
  </configuration>
  <dependencies>
    <!-- This dependency provides the implementation of compiler "jdt": -->
    <dependency>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-compiler-jdt</artifactId>
        <version>0.21.0</version>
    </dependency>
  </dependencies>
</plugin>