Can't access method of companion class from companion object
methods, object, scala
Solution
You are trying to call the method `getTag` in `object EFCriteriaType`. There is no such method in that object. You could do something like:
object EFCriteriaType extends EFCriteriaType("text") {
override def toString = getTag
}
Thus making the companion object a kind of template.
You can access members not normally accessible in a class from a companion object, but you still need to have an instance of the class to access them. E.g:
class Foo {
private def secret = "secret"
def visible = "visible"
}
object Foo {
def printSecret(f:Foo) = println(f.secret) // This compiles
}
object Bar {
def printSecret(f:Foo) = println(f.secret) // This does not compile
}
Here the private method `secret` is accessible from `Foo`'s companion object. Bar will not compile since secret is inaccessible.
Problem
I thought that I can access every method of the companion class from my companion object. But I can't? ``` class EFCriteriaType(tag:String) extends CriteriaType { // implemented method of CriteriaType def getTag = this.tag } object EFCriteriaType { var TEXT: CriteriaType = new EFCriteriaType("text") override def toString = getTag } ``` Compiler error: not found: value getTag What I'm doing wrong?