Created
December 31, 2014 21:24
-
-
Save tylertreat/a24eb6090198db2af7eb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public abstract class LazilyLoadedObject implements InvocationHandler { | |
| private Object target; | |
| @Override | |
| public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | |
| if (target == null) | |
| target = loadObject(); | |
| return method.invoke(target, args); | |
| } | |
| /** | |
| * Loads the proxied object. This might be an expensive operation | |
| * or loading lots of objects could consume a lot of memory, so | |
| * we only load the object when it's needed. | |
| */ | |
| protected abstract Object loadObject(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment