Created
August 20, 2014 11:26
-
-
Save rafaeljesus/8befd85473ea0fc2473f to your computer and use it in GitHub Desktop.
dynamic class using map
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 class Student { | |
| private Map<String, String> properties = new HashMap<String, String>(); | |
| private Map<String, Callable<Object>> callables = new HashMap<String, Callable<Object>>(); | |
| public String getProperty(String key) { | |
| return properties.get(key); | |
| } | |
| public void setProperty(String key, String value) { | |
| properties.put(key, value); | |
| } | |
| public Object call(String key) { | |
| Callable<Object> callable = callables.get(key); | |
| if (callable != null) { | |
| return callable.call(); | |
| } | |
| return null; | |
| } | |
| public void define(String key, Callable<Object> callable) { | |
| callables.put(key, callable); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment