I'm trying to write a generic method that looks like this:
private static <T> Class<? extends T> immutableVersionOfClass(Class<T> clazz) {
return new ByteBuddy()
.subclass(clazz)
.method(not(returns(VOID)))
.intercept(to(GetterInterceptor.class))
.method(returns(VOID))
.intercept(to(SetterInterceptor.class))
.make()
.load(clazz.getClassLoader())
.getLoaded();
}
but when final class is passed as an argument I get an exception:
java.lang.IllegalArgumentException: Cannot subclass primitive, array or final types
I'd like my method to be able to subclass also final classes. Is there any workaround for this problem?