Compile file containing java and scala code

前端 未结 1 1113
无人共我
无人共我 2021-01-20 03:02

Ì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 onl

相关标签:
1条回答
  • 2021-01-20 03:55

    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.

    0 讨论(0)
提交回复
热议问题