是否可能有.java和.scala类之间的循环依赖? [英] is it possible to have a circular dependency between .java and .scala classes?

查看:231
本文介绍了是否可能有.java和.scala类之间的循环依赖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在.java文件中定义了类A,在.scala文件中定义了类B.

类A使用类B,类B使用类A.

如果我使用java编译器,我将有一个编译错误,因为类B尚未编译。如果我使用scala编译器类A将不会被找到。是否有编译器可以一起编译?

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 a compiler that can compile both together?

推荐答案

我认为Scala 2.7.2引入了联合编译模式来做到这一点?

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

您正在使用哪个版本的 scalac ,并且该模式是否已停用?

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

编辑:等一下,当你说scalac导致A类没有被发现 - 你是否意识到你仍然需要编译纯Java文件与 javac 后来? Scalac的联合编译模式实际上不会为Java文件生成 *。class 输出,只是将Scala类与其签名进行编译。因此,你仍然需要编译Java文件后,虽然这不应该是 javac 现在Scala类已经编译的问题。

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.

这篇关于是否可能有.java和.scala类之间的循环依赖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆