I am trying to use Scala as part of the existing Java application and now I have a problem with injection I go into a problem with Setter method (No part framework in this part of the code) How is it treated in Scala's way?
Scala requires the introduction of both val
and var
, but I can not do this because Java settings of objects inject Those who implement a certain interface and intrafes are essence and can not be made an institute.
class ScalaLogic {var service // How to get started? Def setService (srv: OutputService) = {service = srv}
Is there a way to initialize var service
so that I allocate a dependency later in Can i do It must be fully scotched in the entire class.
Try using the class to use null
in Java The moral equivalent is to declare service like this:
var service: option [MyInterface] = any
and
Use the service. Receive ()
or pattern matching
service match {no case => ... case something [MyInterface] => ...}
Comments
Post a Comment