Reputation: 51
I understand the difference between object and class. Object is a singleton with anonymous class type. But in my play framework within xxx.scala.html file, it doesn't recorgnize the object name as type name. It report error that no type found. For instance: Object ABC extends Enumeration{ .... }
In xxx.scala.html, define a variable abc:ABC, it will report no type found error, while other class type can be easily defined in this file.
How can I define an object with explicit class name, so that I can use it?
Upvotes: 0
Views: 192
Reputation: 38045
You could always use ObjectName.type
. For instance:
trait Test
object A extends Test
def test(a: A.type) = a
test(A) // compiles fine
test(new Test{}) // compilation error
Note that in case of object ABC extends Enumeration{...}
you should use ABC.Value
as type of instances:
object ABC extends Enumeration{ val A, B, C = Value}
def test(a: ABC.Value) = a
scala> test(ABC.A)
res0: ABC.Value = A
Upvotes: 1