What I want is a property that is a map with a key of type String, where the value can be either a String OR another map:
Map<String, String or Map<String, String>> traits();
Is this possible in Java?
What I want is a property that is a map with a key of type String, where the value can be either a String OR another map:
Map<String, String or Map<String, String>> traits();
Is this possible in Java?
There are two ways to do it, either your generics or Object.
Map<String, ?> stringObjectMap.get = new HashMap<>();Map<String, Object> stringObjectMap.get = new HashMap<>();if(stringObjectMap.get("key") instanceof Map) return (Map)stringObjectMap.get("key");
else return (String)stringObjectMap.get("key");