neutrino, если я вас правильно понимаю, то вот очень примитивный пример, который можно легко улучшить
| Код | import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Random { }
|
| Код | import java.lang.reflect.Field;
public class Test {
@Random public double i;
public static void main(String[] args) { Test test = new Test(); Class clazz = Test.class;
try { for (Field field : clazz.getFields()) { Field property = clazz.getDeclaredField(field.getName()); if (null != property.getAnnotation(Random.class)) { field.setDouble(test, Math.random()); } } } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); }
System.out.println(test.i); }
}
|
|