Lombok 项目与 Scala 配合得很好吗?
如果我希望我的 Scala 项目与 Java“兼容”,即可以从 Java 代码调用 Scala API(以便非 Scala 程序员也可以做出贡献),是否可以在 Java 中使用 Project Lombok代码?还是两个人相处不好?
我将使用 Scala IDE 在 Eclipse 中进行开发。
编辑:我真正的意思是:Eclipse 中的 Scala 编辑器会看到 Lombok 生成的代码,还是只是我真正输入的 Java 代码?
If I wanted my Scala project to be "compatible" with Java, that is make it practical to call the Scala API from Java code (so that non-Scala programmers can also contribute), would it be possible to use Project Lombok in the Java code? Or do the two of them don't get along well?
I would be developing in Eclipse with the Scala IDE.
EDIT: What I really meant was: will the Scala editor in Eclipse see the code generated by Lombok, or just the Java code I really typed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定你在问什么,因为Scala和Java是字节码级别的互操作,它不关心字节码来自哪里。所以我相信你的使用Lombok注释的Java代码仍然可以从Scala程序中调用。
如果你问 Lombok 提供的那些注释是否可以在 Scala 代码中使用,我认为没有意义,因为大多数这些功能都是由 Scala 本身提供的。
例如,带有
@Data
的类可以是 Scala 中的case 类
。您可以像访问普通类一样在 Java 代码中访问它。
并且
Data
将拥有所有精彩的toString
、equals
、hashcode
...等。I'm not sure what you are asking, since Scala and Java are inter-operation in bytecode level, it doesn't care where the bytecode come from. So I believe your Java code which use Lombok annotation is still could be called from Scala program.
And if you are asking if those annotation Lombok provide could be used in Scala code, I see no point, because most of those feature are provided by Scala itsef.
For example,a class with
@Data
could be acase class
in Scala.And you could access it in Java code just like an normal class.
And
Data
will have all wonderfultoString
,equals
,hashcode
....etc.scala 编辑器部分将很好地“看到”生成的代码。
lombok 所做的大部分事情都遵循一些规范或其他规范,与 scala 相同。 lombok 的不同之处在于 canEqual 和 equals 实现,顺便说一句,这与 scala 为案例类 IIRC 生成的东西完全相同,所以即使是这样也是兼容的:)
免责声明:我是 lombok 项目的核心贡献者。
The scala editor part will 'see' the generated code just fine.
Most of what lombok does follows some spec or other, same as scala. Where lombok deviates is canEqual and equals implementations, which incidentally is the exact same thing scala generates for case classes IIRC, so even that is compatible :)
DISCLAIMER: I'm a core contributor to project lombok.