我有一个简单的类和一个伴随对象的应用方法重载:
case class A(val s: String,
val x: Int,
val y: Int,
val z: Int,
val foo: Int => Int,
val l: Option[List[String]])
object A {
def apply(s: String, x: Int, y: Int, z: Int, foo: Int => Int) =
new A(s, x, y, z, foo, None)
def apply(s: String, x: Int, y: Int, z: Int, foo: Int => Int, l: List[String]) =
new A(s, x, y, z, foo, Some(l))
}
Run Code Online (Sandbox Code Playgroud)
我们还定义一个函数:
def foo(x: Int): Int = x + 1 …Run Code Online (Sandbox Code Playgroud) scala ×1