得到未实现的方法错误,即使我已经实现了它们

getting unimplemented methods error even though I have implemented them

我的 PlaySilhouetteCassandra 应用程序出现以下错误

class UsersRepository needs to be abstract, since: it has 6 unimplemented members. /** As seen from class UsersRepository, the missing signatures are as follows. * For convenience, these are usable as stub implementations. */ // Members declared in com.mohiva.play.silhouette.api.repositories.AuthInfoRepository def add[T <: com.mohiva.play.silhouette.api.AuthInfo](loginInfo: com.mohiva.play.silhouette.api.LoginInfo,authInfo: T): scala.concurrent.Future[T] = ???

def find[T <: com.mohiva.play.silhouette.api.AuthInfo](loginInfo: com.mohiva.play.silhouette.api.LoginInfo)(implicit tag: scala.reflect.ClassTag[T]): scala.concurrent.Future[Option[T]] = ???

def remove[T <: com.mohiva.play.silhouette.api.AuthInfo](loginInfo: com.mohiva.play.silhouette.api.LoginInfo)(implicit tag: scala.reflect.ClassTag[T]): scala.concurrent.Future[Unit] = ???

def save[T <: com.mohiva.play.silhouette.api.AuthInfo](loginInfo: com.mohiva.play.silhouette.api.LoginInfo,authInfo: T): scala.concurrent.Future[T] = ???

def update[T <: com.mohiva.play.silhouette.api.AuthInfo](loginInfo: com.mohiva.play.silhouette.api.LoginInfo,authInfo: T): scala.concurrent.Future[T] = ???

但是,在同一个文件中,我实现了它们

class UsersRepository(session: Session) 
  extends CassandraRepository[UserKeys,User](session, "users", List("bucket","email")) with UserDao with AuthInfoRepository {

        def find(loginInfo:LoginInfo):Future[Option[PasswordInfo]] = Future {
    ...      }

          def add(loginInfo:LoginInfo, authInfo:PasswordInfo):Future[PasswordInfo] = Future {
       ...
          }

          def update(loginInfo:LoginInfo, authInfo:PasswordInfo):Future[PasswordInfo] = {
add(..)//add returns a Future
    ...}

          def save(loginInfo:LoginInfo, authInfo:PasswordInfo):Future[PasswordInfo] =  {
            add(..)//add returns a Future
}

          def remove(loginInfo:LoginInfo):Future[Unit] = Future{
    ...
          }
}

我做错了什么?

好吧,你实际上并没有覆盖它们:

def add[T <: AuthInfo](
  loginInfo: LoginInfo,
  authInfo: T
): Future[T]

def add(
  loginInfo:LoginInfo,
  authInfo: PasswordInfo
):Future[PasswordInfo]

前者采用 任何可以成为 AuthInfo 实例的东西,后者是一个非常特殊的情况,它恰好是 PasswordInfo.

当你将 OOP 混入其中时,例如向上转换到父接口,特化可能实际上不可见,编译器将不得不使用通用(未实现)方法。

在这种情况下,添加 override 关键字更安全,并确保您实际上覆盖了 ??? 实现。