All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.icodegarden.nutrient.lang.Delegateable Maven / Gradle / Ivy

There is a newer version: 3.0.2
Show newest version
package io.github.icodegarden.nutrient.lang;

/**
 * 
 * @author Fangfang.Xu
 *
 */
public interface Delegateable {
	/**
	 * 
	 * @return Nullable
	 */
	Delegateable getDelegator();

	/**
	 * 自身或delegate(并且递归)是否instanceof super
	 * 
	 * @param cla super
	 * @return
	 */
	default boolean instanceOf(Class cla) {
		return ofType(cla) != null;
	}

	default  T ofType(Class cla) {
		if (cla.isAssignableFrom(this.getClass())) {
			return (T) this;
		}
		Delegateable delegatable = getDelegator();
		if (delegatable != null) {
			return delegatable.ofType(cla);
		}
		return null;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy