我是Scala的新手,很抱歉,如果这个问题很明显。
我的计算机上安装了Eclipse Photon。想要编辑Scala代码并生成可运行的jar。棘手的部分是我的计算机(Centos7)无法访问Internet。
我谨记两个潜在的问题/问题:
我在Scala中很陌生。具有名为“ Document”的类和一些作为Document子级的类,例如“ Doc1”和“ Doc2”。所以:
abstract class Document(id: Int, xmlString: String) {
// make some operations and create an instance of subtype
}
case class Doc1 extends Document {
// some subclass specific methods
}
case class Doc2 extends Document {
// some subclass specific methods
}
Run Code Online (Sandbox Code Playgroud)
想要运行Document构造函数,结果由于传递了paramethers而有条件地创建Doc1或Doc2的实例。我应该在“文档”类中添加一些辅助构造函数吗?
任何想法欢迎。
我有一个代码,可以从“ conf.property”文件中加载属性。是否有更好的选择来加载所有属性并将其存储在例如map中?当前方法强制为每个其他属性添加一行代码。
import java.io.File
object SomeObject {
// path to the property file
val path = "/src/main/resources/conf.properties"
// load configuration from file
val conf = ConfigFactory.parseFile(new File(path))
// get properties
val prDataPath = conf.getString("dataPath")
val prContainsHeader = conf.getBoolean("containsHeader").toString
val prMaxRows: Option[Int] = Try(conf.getInt("maxRows")).toOption
// more config variables here...
}
Run Code Online (Sandbox Code Playgroud)