Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@JorgeCastilloPrz
Created December 7, 2014 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JorgeCastilloPrz/fcd339741c7c5a923915 to your computer and use it in GitHub Desktop.
Save JorgeCastilloPrz/fcd339741c7c5a923915 to your computer and use it in GitHub Desktop.
Lazy injection
class GridingCoffeeMaker {
@Inject Lazy<Grinder> lazyGrinder;
public void brew() {
while (needsGrinding()) {
// Grinder created once on first call to .get() and cached.
lazyGrinder.get().grind();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment