I have an Implementation of a Mapper class which accepts Object as parameter in one of the map(Object object)
functions. The rest map(T t)
functions accept Integer or Class etc.
When I try to pass an int it gets Autoboxed into Integer and invokes the map(Object object)
instead of the map(Integer integer)
.
I have done some research for Double Dispatch and saw that I could use the Visitor Pattern. But this does not apply in my case because I do not pass custom Objects that I could have them implement an interface with accept()
.
The aforementioned method accepts every object.
Is there any kind of solution for Double Dispatching with Java objects when you have a method that accepts Object as well?
public BaseMatcher map(Object object) {
return something();
}
public BaseMatcher map(Integer integer) {
return somethingOther();
}
public BaseMatcher map(Class<? extends Exception> klass) {
return somethingOtherOther();
}
The call on these map() functions, would be as follows: foo(Object object) { mapper.map(object); }
which leads to map(Object object)
being invoked.