I have a variant-style object foo
that is capable of behaving as a java.util.Map
and a java.util.List
as well as other plain-old-data types. This object is written in C++ (modelled on the composite pattern) and I'm building a JNI so that I can use it in Java.
In Java, I'm motivated to write
public class foo implements
Streamable,
java.util.Map<String, foo>,
java.util.List<foo>
Then I encounter trouble. For example, I need to implement 3 flavors of remove
:
public foo remove(int index)
public boolean remove(Object key)
public foo remove(Object key)
The first two are for java.util.list
, the final one for java.util.map
. This, of course, is a problem since you cannot have two functions with the same name and parameters but different return types.
Is there a way round this?