我有几个烫洗作业,其中包含一堆常量和一些在所有作业中都一致的函数。当我需要对其中一个进行更改时,我不想在 5 个不同的地方进行更改。我想创建一个 trait 来存储这些东西,但是我在将 trait 引用/导入到我的工作中时遇到了问题。
所以我有一个名为 constants.scala 的文件,其中包含:
trait constants {a bunch of stuff defined here}
在我的一个名为 myJob.scala 的工作中,我尝试定义一个这样的类:
class TrxnAmts(args : Args) extends Job(args) with constants {
All my other code goes here
}
我尝试在 HDFS 中运行 myJob,使用以下命令将 constants.scala 添加到类路径中:
scalding/scripts/scald.rb --hdfs --cp /path/to/constants.scala /path/to/myJob.scala
constants.scala 出现在类路径中,但特征中没有任何内容被识别。我如何使这项工作?我需要编译 constants.scala 并引用类还是先编译成 jar?有没有更好的方法来解决这个问题?
对 OOP 不是很有经验,所以希望我问的不是一个非常基本/显而易见的问题。
谢谢。
最佳答案
是的,您应该在类路径中编译.jar
文件,而不是.scala
或.java
。
使用例如SBT构建它们。
关于scala - 烫伤:从单独的文件中添加特征,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28219073/