How to create a generic method which can call overloaded methods? I tried but it gives a compilation error.
Test.java:19: incompatible types found : java.lang.Object required: T T newt = getCloneOf(t); ^
import java.util.*;
public class Test {
private Object getCloneOf(Object s) {
return new Object();
}
private String getCloneOf(String s) {
return new String(s);
}
private <T> Set<T> getCloneOf(Set<T> set){
Set<T> newSet = null;
if( null != set) {
newSet = new HashSet<T>();
for (T t : set) {
T newt = getCloneOf(t);
newSet.add(newt);
}
}
}
}