Scala and @Inject annotation

I know that the best way to handle dependency injection in Scala is to use tools that were created specifically for the language, but I'm working on a project that needs to integrate some Scala and Java code.

Then I use Google Guice, which implements the JSR-330 specification. Fortunately, during the integration of Guice and Scala, I did not find any problems. I use constructor injection because I have to deal with immutability.

My question is: why in Scala should we use the notation @Inject()before the constructor parameter? Why parathesis ()? The following is an example:

class MyClass @Inject() (val another: AnotherClass) {
  // Body of the class
}
+4
source share
2

, , (val another: AnotherClass) @Inject?

+3

. Scala , ( ) ( )

class Bar @Fooable() ( val i : Int) {

}

i : Bar?

class Bar @Fooable( val i : Int) {

}
+3

Source: https://habr.com/ru/post/1649362/


All Articles