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

解决方案:

加上static

举例如下:

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

 改成

 

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

你可能感兴趣的:(Java编程)