Non-static field ‘func1‘ cannot be referenced from from a static context

解决方案:

加上static

举例如下:

public PairFunction func1 = new PairFunction <Tuple2<Long,Long>, String, Long>()
{
    private static final long serialVersionUID = 1L;
    @Override
    public Tuple2<String, Long> call(Tuple2<Long, Long> tuple)
            throws Exception {
        Random random = new Random();
        int prefix = random.nextInt(10);
        return new Tuple2<String, Long>(prefix + "_" + tuple._1, tuple._2);
    }
};

 改成

 

public static   PairFunction func1 = new PairFunction <Tuple2<Long,Long>, String, Long>()
{
    private static final long serialVersionUID = 1L;
    @Override
    public Tuple2<String, Long> call(Tuple2<Long, Long> tuple)
            throws Exception {
        Random random = new Random();
        int prefix = random.nextInt(10);
        return new Tuple2<String, Long>(prefix + "_" + tuple._1, tuple._2);
    }
};
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页