org.comroid.api.Specifiable Maven / Gradle / Ivy
The newest version!
package org.comroid.api;
import java.util.Optional;
import java.util.function.Supplier;
public interface Specifiable> extends SelfDeclared {
default R as(Class type, Supplier message) throws AssertionError {
return as(type).orElseThrow(() -> new AssertionError(message.get()));
}
default Optional as(Class type) {
if (!isType(type)) {
return Optional.empty();
}
return Optional.of(type.cast(self()));
}
default boolean isType(Class extends B> type) {
return type.isInstance(self());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy