Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala IntelliJ warning "dynamic invocation could be replaced with a constructor invocation"

Why does Intellij give this warning, what does it mean, how can I make it better ?

import akka.actor.Props

object Router {
  def props(config: Config, addresses: Set[Address]): Props =
    Props(classOf[Router], config, addresses)
    // "dynamic invocation could be replaced with a constructor invocation"

If I the Props inplace I get a different warning.

system.actorOf(Props(classOf[Router], config, addresses))
// could be replaced with factory method call

Thanks

like image 650
Stephen Avatar asked Mar 26 '26 07:03

Stephen


1 Answers

Are you missing a class Router definition with a constructor that takes a Config instance and a collection of Address instances? Something like...

class Router(config: Config, addresses: Set[Address]) extends Actor

If so, then try the following slight modification to your companion object.

object Router {

  def props(config: Config, addresses: Set[Address]): Props = {
    Props(new Router(config, addresses))
  }

}

This follows best practices for creating actors and will probably get rid of the warning.

like image 127
davidrpugh Avatar answered Mar 28 '26 21:03

davidrpugh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!