English 中文(简体)
二级医院
原标题:Scalac doesn t find dependent classes
  • 时间:2011-11-06 15:08:37
  •  标签:
  • scala

Im试图用2个最简单的班子编制方案:

class BaseClass

页: 1

class Test extends BaseClass

placed in Test.scala. Issuing command scalac Test.scala fails, cause BaseClass is not found. I don t want to compile classes one by one or using scalac *.scala.

java工程的同一作业:javac 测试。 我在哪里错了?

最佳回答

首先,请看 Java做了些什么:

dcs@dcs-132-CK-NF79:~/tmp$ ls *.java
BaseClass.java  Test.java
dcs@dcs-132-CK-NF79:~/tmp$ ls *.class
ls: cannot access *.class: No such file or directory
dcs@dcs-132-CK-NF79:~/tmp$ javac -cp . Test.java 
dcs@dcs-132-CK-NF79:~/tmp$ ls *.class
BaseClass.class  Test.class

因此,正如你可以看到的那样,Java 实际上汇编了BaseClas。 当你这样做时。 问题是什么:如何做到这一点? 它能知道什么文件汇编?

简而言之,当你在 Java写<代码>extends BaseClas时,你实际上知道几件事。 你们知道从包裹名称中找到这些档案的目录。 它还知道BaseClass要么在目前的档案中,要么在一份名为的档案中。 BaseClass.java 。 如果你怀疑这两种事实,就会试图将档案从目录上转移或重新命名,并且看 Java是否能够汇编。

因此,为什么 t子也一样? 因为它既无所作为! 不管其申报的包裹如何,Schala的档案都可以存放在任何目录中。 事实上,单一Schala档案甚至可以宣布一个以上包裹,从而不可能实行目录规则。 而且,无论名称如何,一个Schala语课程都可以在任何档案中进行。

因此,尽管 Java要求你掌握档案的目录和档案的名称,然后让你从<条码>javac的指挥线上查阅档案,从而获得这些档案。 请你在你看来以任何最好的方式制定你的法典,但要求你告诉它什么地方。

请你看。

问题回答

页: 1

$ scalac Test.scala 
Test.scala:1: error: not found: type BaseClass
class Test extends BaseClass
                   ^
one error found
$ scalac BaseClass.scala
$ scalac Test.scala
$

http://www.ohchr.org。 因此,现在的问题是,你为什么必须逐一汇编档案? 而且,由于Schala的编纂者只是这样做的,所以这种依赖性处理方式就是这样。 其作者可能期望您使用诸如sbtMaven等建筑工具,这样他们就不必双向。





相关问题
How to flatten a List of different types in Scala?

I have 4 elements:List[List[Object]] (Objects are different in each element) that I want to zip so that I can have a List[List[obj1],List[obj2],List[obj3],List[obj4]] I tried to zip them and I ...

To use or not to use Scala for new Java projects? [closed]

I m impressed with Twitter and investigating to use Scala for a new large scale web project with Hibernate and Wicket. What do you think about Scala, and should I use it instead of Java? EDIT: And, ...

Why does Scala create a ~/tmp directory when I run a script?

When I execute a Scala script from the command line, a directory named "tmp" is created in my home directory. It is always empty, so I simply deleted it without any apparent problem. Of course, when I ...

Include jar file in Scala interpreter

Is it possible to include a jar file run running the Scala interpreter? My code is working when I compile from scalac: scalac script.scala -classpath *.jar But I would like to be able to include a ...

Scala and tail recursion

There are various answers on Stack Overflow which explain the conditions under which tail recursion is possible in Scala. I understand the limitations and how and where I can take advantage of tail ...