无结果的类型测试:Option[akka.actor.ActorSystem] 类型的值也不能是 akka.actor.ActorSystem
fruitless type test: a value of type Option[akka.actor.ActorSystem] cannot also be a akka.actor.ActorSystem
我正在使用替罪羊进行静态代码分析,我收到一条警告消息
fruitless type test: a value of type Option[akka.actor.ActorSystem] cannot also be a akka.actor.ActorSystem
这是我的代码
object ActorSystemSetting extends ActorSystemSettingTrait{
val config = ConfigFactory.load()
val log = LoggerFactory.getLogger(this.getClass)
var actorSystem : Option[ActorSystem] = None
def createActorSystem: Option[ActorSystem] = {
actorSystem = Option(ActorSystem("ArteciateActorSystem", config))
actorSystem
}
def getActorSystem : Option[ActorSystem] ={
if (actorSystem == None){
createActorSystem
}
else{
log.debug("ActorSystem is not null")
}
actorSystem
}
}
在这部分我收到了警告信息
线上
case Some(system: ActorSystem) =>
Option(ActorSystemSetting.getActorSystem) match {
case Some(system: ActorSystem) =>
system.actorOf(Props[PaymentViaCreditDeletionActor]
, name = "PaymentViaCreditDeletionActor")
case None => log.debug("ActorSystem is null")
}
}
你需要改变这个
Option(ActorSystemSetting.getActorSystem) match {
仅此而已:
ActorSystemSetting.getActorSystem match {
ActorSystemSetting.getActorSystem
已经 returns Option(ActorSystem)
所以你不需要把它包装在另一个 Option
.
它不起作用,因为您试图将 Option[Option[ActorSystem]]
类型的值与 Some(system: ActorSystem)
类型的值匹配,而 Option[ActorSystem]
类型的值永远无法匹配。
我正在使用替罪羊进行静态代码分析,我收到一条警告消息
fruitless type test: a value of type Option[akka.actor.ActorSystem] cannot also be a akka.actor.ActorSystem
这是我的代码
object ActorSystemSetting extends ActorSystemSettingTrait{
val config = ConfigFactory.load()
val log = LoggerFactory.getLogger(this.getClass)
var actorSystem : Option[ActorSystem] = None
def createActorSystem: Option[ActorSystem] = {
actorSystem = Option(ActorSystem("ArteciateActorSystem", config))
actorSystem
}
def getActorSystem : Option[ActorSystem] ={
if (actorSystem == None){
createActorSystem
}
else{
log.debug("ActorSystem is not null")
}
actorSystem
}
}
在这部分我收到了警告信息 线上
case Some(system: ActorSystem) =>
Option(ActorSystemSetting.getActorSystem) match {
case Some(system: ActorSystem) =>
system.actorOf(Props[PaymentViaCreditDeletionActor]
, name = "PaymentViaCreditDeletionActor")
case None => log.debug("ActorSystem is null")
}
}
你需要改变这个
Option(ActorSystemSetting.getActorSystem) match {
仅此而已:
ActorSystemSetting.getActorSystem match {
ActorSystemSetting.getActorSystem
已经 returns Option(ActorSystem)
所以你不需要把它包装在另一个 Option
.
它不起作用,因为您试图将 Option[Option[ActorSystem]]
类型的值与 Some(system: ActorSystem)
类型的值匹配,而 Option[ActorSystem]
类型的值永远无法匹配。