0

I have .java file and there is code which works. can you explain, is it possible add there some scala code, like change

    int x, y;
int xx = 0;
int yy = 0;
int z = 0;
int flag = 0;

to var x=0 var y=0 var z=0 ....

thanks

2

1 Answer 1

7

Files are the smallest unit of compilation for most languages, including Java and Scala. Thus, you cannot indicate to a Java compiler that it should compile only some of the file and to the Scala compiler that it should compile other parts.

You can, however, mix classes written in Java with those written in Scala, as long as the classes are in their own appropriate files.

(Actually, it's possible to execute a line of Scala at a time using the REPL interpreter, but this can't merge the way you want with Java code because, firstly, the Java compiler doesn't know what you're doing, and secondly, the Scala is actually secretly wrapping the statements in classes to make it all work.)

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.