我对正确理解类和伴侣对象的使用存在问题。案例分类和伴随对象
当定义一个case类时,它的陪伴对象随它而来,但是定义一个与case类同名的对象的结果是什么?它是否覆盖伴侣对象?以及如何访问案例类参数?
例如在TestCaseClass.scala文件I定义如下:
case class TestCaseClass(att1: String, att2: Int, att4s: List[String])
object TestCaseClass {
def iWantDoSomethingWithMyParams: String = {
att1 + " " + att2
}
// Other functions
}
object AnotherTestCaseClass {
def iWantDoSomethingWithTestCaseClassParams: String = {
// How to access TestCaseClass.att1
TestCaseClass.att1 + " " + TestCaseClass.att2
}
def iWantGetAllAttr4: List[String] = {
// ???
}
}
http://stackoverflow.com/questions/5827510/how-to-override-apply-in-a-case-class-companion –