public interface FieldGetter extends Function, Serializable {
@SneakyThrows
default String getFieldName() {
String methodName = getMethodName();
if (methodName.startsWith("get")) {
methodName = methodName.substring(3);
}
return CharSequenceUtil.lowerFirst(methodName);
}
@SneakyThrows
default String getMethodName() {
return getSerializedLambda().getImplMethodName();
}
@SneakyThrows
default Class> getFieldClass() {
return getReturnType();
}
@SneakyThrows
default SerializedLambda getSerializedLambda() {
Method method = getClass().getDeclaredMethod("writeReplace");
method.setAccessible(true);
return (SerializedLambda) method.invoke(this);
}
@SneakyThrows
default Class> getReturnType() {
SerializedLambda lambda = getSerializedLambda();
Class> className = Class.forName(lambda.getImplClass().replace("/", "."));
Method method = className.getMethod(getMethodName());
return method.getReturnType();
}
}