0

我正在尝试根据现有缓存填充另一个原子引用。我想使用 lambdas 来简化代码(需要更少的锅炉代码),但它似乎不起作用。

这有效:

class PutFunction implements IFunction<Graph<Long,Long>,Graph<Long,Long>>{
    private Long key;

    public PutFunction(Long key) {
        this.key = key;
    }

    public Graph<Long,Long> apply(Graph<Long,Long> graph){
        graph.addVertex(key);
        return graph;
    }
}

getGraphCache().alter(new IFunction<Graph<Long,Long>,Graph<Long,Long>>(){
    public Graph<Long,Long> apply(Graph<Long,Long> graph){
       graph.addVertex(event.getValue().getId());
       return graph;
    }
});

当我切换到下面的 lambda 语法时,它会给出序列化错误:

getGraphCache().alter((IFunction<Graph<Long, Long>, Graph<Long, Long>>) graph -> {
   graph.removeVertex(event.getValue().getId());
   return graph;
});

错误
com.hazelcast.nio.serialization.HazelcastSerializationException: Failed to serialize 'com.portal.objects.ObjectGraphEntryListener$$Lambda$61/1840645556'

有没有人让它与 lambdas 一起工作?

ObjectGraphEntryListener

hazelcast.xml

4

0 回答 0