I would like to create a base class that extends all classes in my program. The only thing I wanted to do was find a single way to store all instance variables inside the object.
What I came up with is to use a HashMap to store key / value pairs for an object, and then set these values ββusing the get and set method.
The code I have for this is as follows:
package ocaff; import java.util.HashMap; public class OcaffObject { private HashMap<String, Object> data; public OcaffObject() { this.data = new HashMap<String, Object>(); } public Object get(String value) { return this.data.get(value); } public void set(String key, Object value) { this.data.put(key, value); } }
Although this works functionally, I'm curious if there are any real problems with this implementation, or if there is a better way to do this?
In my daily work, I am a PHP programmer, and my goal was to mimic the functionality that I used in PHP in Java.
Josh pennington
source share