Unchecked call to ‘mapoPair(PairFunction<T,K2,V2>)‘ as a member of raw type
生活随笔
收集整理的這篇文章主要介紹了
Unchecked call to ‘mapoPair(PairFunction<T,K2,V2>)‘ as a member of raw type
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
先解釋下這里面的T,K2,V2啥意思。
這個是官方文檔隨便標記的,意思是:
| PairFunction<T, K, V> | T => Tuple2<K, V> |
也就是說,T是入口參數,K和V是返回的一個二維數組。
但是注意哈,這里是范型,而不是寫死的函數。
如果是寫死的函數,我們知道函數名前面是返回的變量的類型。
但是由于是泛型,這里函數名前面同時寫了入口參數類型以及返回變量類型。
?
那么上面這個同時警告要怎么消除呢?
其實是因為忘記寫泛型了。如下:
private static PairFunction func3 = new PairFunction <Tuple2<Long,Long>, Long, Long>() {private static final long serialVersionUID = 1L;public Tuple2<Long, Long>call(Tuple2<Long, Long> tuple)throws Exception //這個地方使用了函數模板,在java中稱為范型{return new Tuple2<Long, Long>(tuple._2, tuple._1);} };改成:
private static PairFunction<Tuple2<Long,Long>,Long,Long> func3 = new PairFunction <Tuple2<Long,Long>, Long, Long>() {private static final long serialVersionUID = 1L;public Tuple2<Long, Long>call(Tuple2<Long, Long> tuple)throws Exception //這個地方使用了函數模板,在java中稱為范型{return new Tuple2<Long, Long>(tuple._2, tuple._1);} };即可,注意上面紅色部分是新增的。
?
?
總結
以上是生活随笔為你收集整理的Unchecked call to ‘mapoPair(PairFunction<T,K2,V2>)‘ as a member of raw type的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 和平精英的空投洞在哪里
- 下一篇: 自动点击器如何设置滑动间隔