I have following interface:
public interface EntityCloneService<T extends AbstractNamedEntityBase> {
/**
* Given a UUID load the Entity Type.
*
* @param uuid
* @return Entity From DB and
*/
public T getByUuid(UUID uuid);
/**
* Given the Existing Entity, clone it and save in DB, then return clone instance.
*/
public T getCloneAndSave(T existingEntity) throws Exception;
}
Now I have Generic Service, where I have
@Component
public class GenericEntityCloneService {
private static final Map<String,EntityCloneService<? extends AbstractNamedEntityBase>> registration =
new HashMap<String,EntityCloneService<? extends AbstractNamedEntityBase>>(); // here we have registration of all entity by name to service actual implementation.
public void clone(AbstractNamedEntityBase existingEntity) {
EntityCloneService<? extends AbstractNamedEntityBase> service = registration.get("SOME KEY");
AbstractNamedEntityBase entity = service.getByUuid(ref.getUuid()); // THIS WORKS because it up casting.
service.getCloneAndSave(entity); // now how do I pass entity object such that
}
}
When I try to compile this code does not compile. I know that getCloneAndSave() I am passing the type AbstractNamedEntityBase which is not allowed. So how do I make a call service.getCloneAndSave(entity); Any help is greatly appreciated. I am using java 8.