Pregunta

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?

¿Fue útil?

Solución

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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top