object User extends Magic[User]().using(“users”) can not compiled

孤街浪徒 提交于 2019-12-24 02:43:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!