Created
December 7, 2014 16:09
-
-
Save JorgeCastilloPrz/fcd339741c7c5a923915 to your computer and use it in GitHub Desktop.
Lazy injection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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