Skip to content

Instantly share code, notes, and snippets.

@rafaeljesus
Created August 20, 2014 11:26
Show Gist options
  • Select an option

  • Save rafaeljesus/8befd85473ea0fc2473f to your computer and use it in GitHub Desktop.

Select an option

Save rafaeljesus/8befd85473ea0fc2473f to your computer and use it in GitHub Desktop.
dynamic class using map
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