package speiger.src.coreengine.ui.gui.component.base;

public interface ICastable 
{
	@SuppressWarnings("unchecked")
	public default <T> T cast() {
		return (T)this; }
	
	@SuppressWarnings("unchecked")
	public default <T> T cast(Class<T> clz) {
		return (T)this;
	}
	
	@SuppressWarnings("unchecked")
	public default <T> T tryCast(Class<T> clz) {
		return clz.isInstance(this) ? (T)this : null;
	}
	
	@SuppressWarnings("unchecked")
	public static <T> T cast(Object obj) {
		return (T)obj;
	}
	
	@SuppressWarnings("unchecked")
	public static <T> T cast(Object obj, Class<T> clz) {
		return (T)obj;
	}
	
	@SuppressWarnings("unchecked")
	public static <T> T tryCast(Object obj, Class<T> clz) {
		return clz.isInstance(obj) ? (T)obj : null;
	}
}