Ìs it possible to compile file that contains both scala and java code? I'm doing online course and was given java source files, which I need to extend. Do I have to use only Java in already existing files?
1 Answer
You cannot have both Java and Scala in one file. After all it's either .java or .scala.
However you are free to:
- extend Java classes in Scala (and vice-versa)
- implement Java interfaces in Scala (syntax is the same as for extending traits)
- extend Scala traits in Java (syntax is the same as for implementing Java interfaces)
...as long as they are in different files.