September 2015
Intermediate to advanced
250 pages
6h 40m
English
Before diving into mixing Java and Scala, let’s first look at using Scala classes from Scala. If you’ve created Scala classes in separate files, compile them to bytecode using the Scala compiler scalac. Then drop them into a JAR file using the jar tool. In the next example, we compile two classes, Person and Dog, and then create a JAR from the resulting class files. Let’s take a look at the classes first:
| Intermixing/Person.scala | |
| | class Person(val firstName: String, val lastName: String) { |
| | override def toString : String = firstName + " " + lastName |
| | } |
| Intermixing/Dog.scala | |
| | class Dog(val name: String) { |
| | override def toString = name |
| | } |
Here are the commands to compile and create the ...
Read now
Unlock full access