The answer is no. Because there is no way to know which class will replace your generic type E at compile time if you don't bind it to the type .
The Java cloning method is shallow, for deep cloning we need to provide our own implementation
The workaround for him is to create such a contract
public interface DeepCloneable { Object deepClone(); }
and the developer must have his own deep clone of logic
class YourDeepCloneClass implements DeepCloneable { @Override public Object deepClone() {
and it can be called as shown below, where the generic type E is a restricted type
class Test<E extends DeepCloneable> { public void testDeepClone(E arg) { E e = (E) arg.deepClone(); } }
source share