public static class Oya {
String name;
public Oya(String name) {
super();
this.name = name;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Oya [name=" + name + "]";
}
}
public static void main(String[] args) throws GridException {
try (Grid grid = GridGain.start(
System.getProperty("user.home") + "/gridgain-platform-os-6.1.9-nix/examples/config/example-cache.xml")) {
GridCache<Integer, Oya> cache = grid.cache("partitioned");
boolean success2 = cache.putxIfAbsent(3, new Oya("3"));
log.info("Current 3 value = {}", cache.get(3));
cache.transform(3, (it) -> new Oya(it.name + "-transformed"));
log.info("Transformed 3 value = {}", cache.get(3));
}
}
- 启动另一个 GridGain 节点。
- 运行代码。它应该打印:
3-transformed
- 注释
putxIfAbsent()
代码。 - 运行代码。我希望它打印出来:
3-transformed
但得到null
了
String
如果我将缓存值更改为(如在GridGain Basic Operations 视频中)或 Java 内置值,代码将起作用,但不适用于我自己的自定义类。