You can do something in this direction.
Class<? extends SuperClass> clazz = var.getClass(); SuperClass varCopy = clazz.newInstance();
Note that clazz.newInstance() will throw an IllegalAccessException if it does not have an empty default constructor.
source share