Even if it is an old thread, maybe some is interested.
If it is an option to you to use the same method inside the same class and archive different return types, use generics: Oracle Lesson Generics
Simple example for generic value holder class:
class GenericValue<T> {
private T myValue;
public GenericValue(T myValue) { this.myValue = myValue; }
public T getVal() { return myValue; }
}
And use it like this:
public class ExampleGenericValue {
public static void main(String[] args) {
GenericValue<Integer> intVal = new GenericValue<Integer>(10);
GenericValue<String> strVal = new GenericValue<String>("go on ...");
System.out.format("I: %d\nS: %s\n", intVal.getVal(), strVal.getVal());
}
}
... will result in the following output:
I: 10
S: go on ...