
org.revenj.patterns.Generic Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of revenj-core Show documentation
Show all versions of revenj-core Show documentation
DSL Platform compatible backend (https://dsl-platform.com)
The newest version!
package org.revenj.patterns;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
public abstract class Generic {
public final Type type;
protected Generic() {
Type superclass = getClass().getGenericSuperclass();
if (superclass instanceof Class) {
throw new RuntimeException("Missing type parameter.");
}
this.type = ((ParameterizedType) superclass).getActualTypeArguments()[0];
}
@SuppressWarnings("unchecked")
public T resolve(ServiceLocator locator) {
try {
return (T) locator.resolve(type);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy