You are trying to call the getTag
method on object EFCriteriaType
. There is no such method in this object. You can do something like:
object EFCriteriaType extends EFCriteriaType("text") { override def toString = getTag }
Thus, creating a companion object is a kind of template.
You can access members that are not normally available in the class from a companion object, but you still need to have an instance of the class to access them. For instance:
class Foo { private def secret = "secret" def visible = "visible" } object Foo { def printSecret(f:Foo) = println(f.secret)
Here, the private secret
method is accessible from the Foo
of the companion object. The bar will not compile because the secret is not available.
source share