Gremlin java 设置顶点标签抛出 ClassCastException

Gremlin java set vertex label throws ClassCastException

如果顶点 ID 不存在并设置标签,我正在尝试使用 Gremlin java 创建一个顶点, 首先我试试这个:

GraphTraversalSource graph = TinkerGraph.open().traversal();
graph.V("0").fold().coalesce(__.unfold(),__.addV()).property(T.label, "0").next()

但抛出异常:

java.lang.ClassCastException: org.apache.tinkerpop.gremlin.structure.T cannot be cast to java.lang.String

那我试试这个:

GraphTraversalSource graph = TinkerGraph.open().traversal();
graph.V("0").fold().coalesce(__.unfold(),__.addV().property(T.label, "0")).next()

这有效。

想知道为什么第一段代码不起作用。
对于我的用例,我需要以第一种方式进行,稍后再决定 属性。

您不能更改已存在的顶点上的标签。在第二种情况下,您将标签添加为顶点创建的一部分。