I'm using scala and Guice, in particular the Assisted Injection. I'm having
a problem with private Var. If i declare the constructor injected fields of
my client class private as it can be seen immediately below i get an
error:
*have firstname (Maatary) used with an object that had no public field or
method named firstname or getFirstname (TraversableLike.scala:244)*
I know that when private the var gettter and setter are private, but this
is precisely what i want. An injection simply by the constructor and no
access to my field from the exterior. But i got that issue. Any help ?
trait FieldInjectClientFactory {
def createFieldInjectCLient(@Assisted("first") afirstname: String, @
Assisted("last") alastname: String):FieldInjectionClient
}
class FieldInjectionClient private {
private var firstname: String = ""
private var lastname: String = ""
@Inject
val injected: String = ""
@Inject
def this(@Assisted("first") afirstname: String, @Assisted("last")
alastname: String) {
this()
firstname = afirstname
lastname = alastname
}
override def toString() : String = {
"firstname: " + firstname + ", lastname: " + lastname + ", injected: "+
injected
}
}
class fieldinjectmodule extends AbstractModule {
def configure() : Unit = {
bind(classOf[String]).toInstance("test bind")
val fb = new FactoryModuleBuilder()
install(fb.build(classOf[FieldInjectClientFactory]))
}
}
val fieldInjector = Guice.createInjector(new fieldinjectmodule())
val factory = fieldInjector.getInstance(classOf[FieldInjectClientFactory])
val client = factory.createFieldInjectCLient("Maatary", "Okouya")
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.