2017-07-28 53 views
1

(弗林克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. 

當使用DataStream<MyGenericClass<T>>其中:

public class MyGenericClass<T> extends Tuple2<String, T> { 
    ... 
} 

我怎樣才能解決沒有.returns(..)解決方案的問題?
你可以舉一個例子來說明如何實現一個類型信息工廠或者如何爲MyGenericClass實現ResultTypeQueryable

預先感謝您

回答

0

免責聲明:我的答案是基於這樣的假設您正在使用Java8 lambda表達式

我真的不知道,但根據弗林克文檔 - 這是一個問題,因爲「OpenJDK和Oracle JDK的javac等編譯器拋棄了所有與Lambda表達式相關的泛型參數,這意味着將Tuple2或Collector聲明爲Lambda函數輸入或輸出參數的類型將在編譯時修剪爲Tuple2或Collector .class文件,這對於Flink編譯器來說信息太少。「

根據相同的Fink文檔 - 「只有Eclipse JDT編譯器保留了安全地使用整個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> 

有關詳細信息,請參閱此鏈接 - https://ci.apache.org/projects/flink/flink-docs-release-1.3/dev/java8.html