Java 如何使用注释@MyFormat(";%td.%<;tm.%<;tY";设置getBirthday()的格式
我如何生成一个类,该类接受Person实例并以字符串形式返回生日,而不是以@MyFormat注释的值格式化的日期,而不用手工编写该子类 目的是使用生成的实例生成HTML页面Java 如何使用注释@MyFormat(";%td.%<;tm.%<;tY";设置getBirthday()的格式,java,bytecode,byte-buddy,Java,Bytecode,Byte Buddy,我如何生成一个类,该类接受Person实例并以字符串形式返回生日,而不是以@MyFormat注释的值格式化的日期,而不用手工编写该子类 目的是使用生成的实例生成HTML页面 班级人员{ @MyFormat(“%td.%%我不完全确定我是否理解您试图实现的目标。以下代码正在创建一个您不使用的Person子类: new ByteBuddy() .subclass(person.getClass()) .method(isAnnotatedWith(MyFormat.class)) .in
班级人员{
@MyFormat(“%td.%%我不完全确定我是否理解您试图实现的目标。以下代码正在创建一个您不使用的Person
子类:
new ByteBuddy()
.subclass(person.getClass())
.method(isAnnotatedWith(MyFormat.class))
.intercept(MethodDelegation.to(MyFormatInterceptor.class))
.make()
.load(person.getClass().getClassLoader(),
ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
当您在运行时使用此生成的子类时,调用getBirthday
方法会导致ClassCastException
,因为字符串
值不能转换为日期
。即使通过反射调用方法,Byte Buddy也不会更改返回类型