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

io.github.icodegarden.commons.lang.Delegatable Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package io.github.icodegarden.commons.lang;

/**
 * 
 * @author Fangfang.Xu
 *
 */
public interface Delegatable {
	/**
	 * 
	 * @return Nullable
	 */
	default Delegatable getDelegatable() {
		return null;
	}

	/**
	 * 自身或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;
		}
		Delegatable delegatable = getDelegatable();
		if (delegatable != null) {
			return delegatable.ofType(cla);
		}
		return null;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy