为什么在使用混合项目时,Scala 案例 class 中的 Lombok 在 Java class 中无法访问?

Why is Lombok in a Scala case class inaccessible in a Java class when using Mixed project?

我有一个简单的 Spring 引导应用程序和 Scala class...

case class TestThing(val name: String ){
  @Getter
  @Setter
  var value = null
  def getMap = {
    val list: List[Item] = List(Item("1", "Foo"), Item("2", "Bar"))
    val map = list.map(item => item.key -> item).toMap
    map("1")
  }
}

现在我正尝试从 java class 访问 getter 和 setter 函数,如下所示...

@GetMapping("/other")
public String index(){
    TestThing thing = new TestThing("My Name");
    thing.setValue("Test");
    return "Hello World from me "+thing.getMap().value()+"||"+thing.getValue();
}

thing.getMap() 工作正常但我得到以下 getters 和 setters 的编译错误...

  error: cannot find symbol
        return "Hello World from me "+thing.getMap().value()+"||"+thing.getValue();
                                                                       ^
  symbol:   method getValue()
  location: variable thing of type TestThing

我错过了什么?我发现了这个问题 (Error compiling Java/Scala mixed project and Lombok),但它是相反的,似乎没有帮助。

Lombok 不适用于 Scala。就那么简单。 (甚至在您链接的问题中描述了原因)。 Scala 中的 @Getter 和 @Setter 注释 类 永远不会被处理,也永远不会生成访问器。

它也完全不需要,因为案例 类 生成:toStringequalshashcode 吸气剂和 setter。如果你想要 Java Bean 访问器,你可以使用 @BeanProperty 注释。

import scala.beans.BeanProperty

case class TestThing(val name: String ){
  @BeanProperty
  var value: String = null
}
val test = TestThing("test")
test.getValue // null
test.setValue("test")
test.getValue // "test"