public final class Lazy<T> extends Object
Provider
, calling get()
will produce an instance of T
.
Unlike a Provider
, the same instance will be returned for every future call to get()
. Different
Lazy
instances are independent and will return different instances from get()
.
Lazy
works automatically for unqualified bindings, as long as just-in-time bindings are enabled. For
qualified bindings, or if explicit bindings are requred, use LazyBinder
:
// Either separately... bind(Dependency.class) .annotatedWith(Names.named("name")) .to(RealDependency.class); LazyBinder.create(binder()) .bind(Dependency.class) .annotatedWith(Names.named("name")); // ... or in one go LazyBinder.create(binder()) .bind(Dependency.class) .annotatedWith(Names.named("name")) .to(RealDependency.class); ... @Inject @Named("name") Lazy<Dependency> lazy;
public T get()
T
.Copyright © 2014. All rights reserved.