18

I want to use morphia for my data access, but I also want to try to use Scala for web content. Is it possible to mix and match Java and Scala files, or if i choose to use Java, i have to stick to Java?

I know this is a newbie question, I'm coming from the python/django world, I really like Play, did some Java programming in the past, but Scala looks very interesting, so while I'm a bit afraid to fully jump into Scala, I want to be able to use it alongside Java.

Thanks for all the help.

2 Answers 2

28

You can definitevelly use both java and scala since Play is a JVM framework, not a Java nor a Scala one.

So in controllers, you could have a ScalaApplication.scala and a JavaApplication.java if you wish.

And they are callable (redirectable, ...) from each other.

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

1 Comment

no problem... if you consider it's ok, don't forget to accept it... this is why stackoverflow works fine ;)
7

Yes ,it is possible to use both Java and Scala files in a Play app. In fact the template system itself demonstrates an aspect of this. You can also have a mix of Scala and Java Controllers. (I haven't tested it yet but I presume it should be possible to mix Scala and Java Models as well ).

This is because both Scala and Java files are changed into nearly identical bytecode and hence the JVM is agnostic to the language in which the code was written in.

Note: When creating a new application from the Play console an option is given to create a Java Scala or empty project.This option sets the default configuration for the building and mainly deals with the imports that are automatically available in the templates.It does not prevent you from adding code from the other language later

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.