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?
Lombok is just a tool to make your life easy. It does not provide any assistance or support for clean code. If clean code and design principles are not of importance (trust me it's not that bad as it sounds in most of the cases), then using Lombok to simplify development process is the best option.
Also, I really discourage using any Lombok annotation that modifies the code. If you take @Data, @Getter, @Setter, @AllArgsConstructor adds new codes into the existing source code without modifying the code we wrote.
Lombok Dependency Note: If you're using a Spring Boot POM, Project Lombok is a curated dependency. Thus, you can omit the version (which will then be inherited from the Spring Boot parent POM).
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 a case class
in Scala.
case class Data(name: String, value: Int)
And you could access it in Java code just like an normal class.
Data d1 = new Data("someData", 1); // Using constructor
Data d2 = Data.apply("someData", 1); // Or using factory
And Data
will have all wonderful toString
, equals
, hashcode
....etc.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With