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);
    }
};

即可,注意上面红色部分是新增的。