- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Case class and companion Object
Thu, 2009-02-26, 15:46
Hi,
Is it not possible to have a case class and add methods to its
companion object? I understand that a companion object is generated
for the case class, which is fine but I would like to add methods to it.
Example:
case class Foo(name:String)
object Foo{
def apply()=new Foo("defaultname")
}
Jesse
Yes, it is. It won't work in the interpreter though.