クラスとそのコンパニオンオブジェクトの使用を正しく理解することに問題があります。ケースクラスとコンパニオンオブジェクト
ケースクラスを定義する際には、付属のコンパニオンオブジェクトがありますが、ケースクラスと同じ名前のオブジェクトを定義した結果はどうなりますか?コンパニオンオブジェクトをオーバーライドしますか?そして、ケースクラスのパラメータにアクセスする方法?多くの特別な意味を持っていないclass
(またはtrait
)とobject
同じ名前を与える
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 –