为什么我不能将伴随对象传递给函数
why can't I pass companion object to a function
我正在研究 Silhouette 框架并正在创建类型 Environment
的变量。它的伴随对象具有签名
def apply[E <: Env](
identityServiceImpl: IdentityService[E#I],
authenticatorServiceImpl: AuthenticatorService[E#A],
requestProvidersImpl: Seq[RequestProvider],
eventBusImpl: EventBus
对于 authenticatorServiceImpl
参数,我认为我可以传递伴随对象 SessionAuthenticatorService
(如 https://github.com/mohiva/play-silhouette/blob/master/silhouette/app/com/mohiva/play/silhouette/impl/authenticators/SessionAuthenticator.scala
中所定义)但是当我尝试时:
val sessionEnv = com.mohiva.play.silhouette.api.Environment[SessionEnv](new UserService(userRepository),SessionAuthenticatorService() ,CredentialsProvider(),EventBus())
我收到错误
com.mohiva.play.silhouette.impl.authenticators.SessionAuthenticatorService.typ does not take parameters.
我删除了 ()
但出现了另一个错误:
found : SessionAuthenticatorService.type [error] required: AuthenticatorService[components.SessionEnv#A]
看来我的概念不太对。为什么我不能通过 SessionAuthenticatorService
?
伴生对象不是伴生对象的实例 class。其实是另一种类型。
class ABC(val arg: Int)
object ABC
val abc: ABC = new ABC(9)
val xyz: ABC.type = ABC
abc.arg //res0: Int = 9
xyz.arg //Error: value arg is not a member of object A$A1661.this.ABC
我正在研究 Silhouette 框架并正在创建类型 Environment
的变量。它的伴随对象具有签名
def apply[E <: Env](
identityServiceImpl: IdentityService[E#I],
authenticatorServiceImpl: AuthenticatorService[E#A],
requestProvidersImpl: Seq[RequestProvider],
eventBusImpl: EventBus
对于 authenticatorServiceImpl
参数,我认为我可以传递伴随对象 SessionAuthenticatorService
(如 https://github.com/mohiva/play-silhouette/blob/master/silhouette/app/com/mohiva/play/silhouette/impl/authenticators/SessionAuthenticator.scala
中所定义)但是当我尝试时:
val sessionEnv = com.mohiva.play.silhouette.api.Environment[SessionEnv](new UserService(userRepository),SessionAuthenticatorService() ,CredentialsProvider(),EventBus())
我收到错误
com.mohiva.play.silhouette.impl.authenticators.SessionAuthenticatorService.typ does not take parameters.
我删除了 ()
但出现了另一个错误:
found : SessionAuthenticatorService.type [error] required: AuthenticatorService[components.SessionEnv#A]
看来我的概念不太对。为什么我不能通过 SessionAuthenticatorService
?
伴生对象不是伴生对象的实例 class。其实是另一种类型。
class ABC(val arg: Int)
object ABC
val abc: ABC = new ABC(9)
val xyz: ABC.type = ABC
abc.arg //res0: Int = 9
xyz.arg //Error: value arg is not a member of object A$A1661.this.ABC