I am rewriting a large Java codebase to use Scala because the data structures are better described using mixins instead of inheritance. About 30% of the code creates the data structures, and about 70% manipulates the data structures in a profoundly procedural and mutable manner. I am starting to rewrite the 30% in Scala to create the data structures as mixins of traits, but I wish to keep the 70% in Java to preserve my sanity. Currently I am using VSCode not by choice, because I can’t get my preferred Intellij IDEA to compile even the most basic code. Is it correct to assume that the Java code can still manipulate the data structures with setters/getters even though the instances are now compositions instead of inheritance chains? Will the recommended file directory tree for sbt automatically make the Java and Scala code know about each other (and if not, how to specify this)? I am reading the previously recommended books (which are excellent by the way), but they do not cover these codebase matters in detail.
1 Like
Yes - the trait works as a Java interface too. You might need to use the @BeanProperty
annotation if your Java code is some enterprise Spring thing that assumes a naming convention on getters and setters for reflection.
I sometimes start with a Java interface and implement in Scala if I’m really worried about compatibility.
Yes, stick the Scala code under src/main/scala
, src/test/scala
and the Java code under src/main/java
, src/test/scala
.
There is an SBT option compileOrder
you may need to fiddle with, see: sbt Reference Manual — Java Sources.
IntelliJ and VSCode will pick up the structure from an SBT project.