开发者

is it possible to have a circular dependency between .java and .scala classes?

Lets say I have class A defined in .java file, and class B defined in .scala file.

class A use class B and class B use class A.

If I use java compiler I will have a compilation error because class B is not compiled yet. If I use scala compiler class A will not be found. Is there 开发者_StackOverflowa compiler that can compile both together?


I thought that Scala 2.7.2 introduced a joint compilation mode to do exactly this?

Which version of scalac are you using, and is it running with this mode disabled?

Edit: Wait a second, when you say scalac leads to Class A not being found - did you realise that you still need to compile the pure Java files with javac afterwards? Scalac's joint compilation mode doesn't actually produce *.class output for the Java files, merely compiles the Scala classes against their signatures. Hence you still need to compile the Java files afterwards, though this shouldn't be a problem for javac now that the Scala classes have been compiled.


Create fake class B in Java. Declare there only members which are referenced from A. Methods' bodies can be empty. Compile A.java and B.java together. Then throw away B.class and compile B.scala.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜