问题
When using Anorm I want to use a different table name for the User case class:
object User extends Magic[User]().using("users")
But I get the following compilation error:
The file /app/models/User.scala could not be compiled. Error raised is : ';' expected but '.' found.
object User extends MagicUser↓.using("users")
Is this a bug of Anorm?
回答1:
Clearly not a bug, your code is not valid scala. You could do that instead :
lazy val User = new Magic[User].using("users")
(the convention would be lowercase "user", capital left so that it is equivalent to your intended code)
object is a declaration, not an expression. An object declaration is
object ObjectName extends Ancestor(ancestor_constructor_arguments) {
// body: data, method and initialization code
}
with most parts optional.
You have to do your adaptation either through constructor arguments or initialization code in the body of the object.
As you add no behavior to class Magic, there seems to be no need to declare an object anyway.
来源:https://stackoverflow.com/questions/6426593/object-user-extends-magicuser-usingusers-can-not-compiled