I want to store different types in a Map like this:
public Map< String, Void > common;
MyClass object = new MyClass();
common.put( "Object1", object );
and then use it like this:
Void object = common.get( "Object1" );
( ( MyClass )object ).runAnyFunction();
This only works if I create my own empty class named Void and extends all classes I will put in the Map with Void. So problem solved, unless…
Isn’t there already a Void in Java? If I don’t create my own Void class is still works. Until I get to the casting where I try to .runAnyFunction(). Maybe if I tried to extend my classes with Void – but that only works with the Void I create, not Java’s Void.
It really comes down to if I really need to create my own empty Void class. Or if I can use Java’s own Void?
Why you don’t use Object? All Java classes a directly or indirectly subclasses from Object.