I am looking for a good way to have different implementations of the same method which is defined in an interface but with different parameter types. Would this be possible?
Here's an example of Generics
Database
public interface Database {
public T createNode(...);
public void modifyNode(T id, ...);
...
}
Database1
class Database1 implements Database {
@Override
public Long createNode(...) {
...
long result = // obtain id of created node
return result;
}
@Override
public void modifyNode(Long id, ...) {
...
// use id
}
}
Database2
public class Database2 implements Database {
@Override
public SomeObject createNode(...) {
...
SomeObject result = // obtain id of created node
return result;
}
@Override
public void modifyNode(SomeObject id, ...) {
...
// use id as (SomeObject)id
}
}
Btw, don't worry about autoboxing. You are using JDK >= 5 since there are @Override annotations.