io.github.icodegarden.nutrient.lang.IdObject Maven / Gradle / Ivy
package io.github.icodegarden.nutrient.lang;
import java.util.List;
import io.github.icodegarden.nutrient.lang.util.ClassUtils;
/**
*
* @author Fangfang.Xu
*
*/
public interface IdObject {
ID getId();
void setId(ID id);
@SuppressWarnings("all")
public static void setIdIfNecessary(Object id, Object target) {
if (target instanceof IdObject && ((IdObject) target).getId() == null) {
List> types = ClassUtils.getGenericInterfaceTypes(target, IdObject.class);
if (!types.isEmpty() && types.get(0).equals(id.getClass())) {
/**
* 要求参数类型相同
*/
((IdObject) target).setId(id);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy