I would like to ask what's the difference between
bindConstant().annotatedWith(Names.named("keepAliveInterval")).to(60);
and
bind(Integer.TYPE).annotatedWith(Names.named("keepAliveInterval")).toInstance(60);
I would like to load all my configuration properties with Names.bindProperties(binder(), prop); in my module and I discovered that it uses the latter one for binding properties.
Thanks, regards
Marek
I think reasons to use bindConstant()
are:
bindConstant().to(foo)
. Since the types you bind with it are primitives and String
s, it's unlikely that an annotation-less binding would make sense for any of them.bindConstant()
binds an int
to Integer.class
rather than Integer.TYPE
, not sure if that matters).I think Names.bindProperties
doesn't use bindConstant
just because it's internal code and a little more code is OK to skip a step or two in the process of making a binding. In your own modules, I'd just use bindConstant
because it's easy and more clear.