3

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

9

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.