lundi 14 mars 2016

get paramter modifier reflection

I have a SimplePojo class and I would like to retrieve parameter modifier at run-time using reflection.

However, it does not seem to work ... SSCEE

public final class SimplePojo {

    private final String name;
    private final int age;

    public SimplePojo(String name, final int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }
}

And this is how I try to check if parameter modifier is FINAL

for (Class<?> paramClazz : method.getParameterTypes()) {
            if (!Modifier.isFinal(paramClazz.getModifiers())) {
                throw new ConstraintViolationException(
                        String.format("Parameters of method '%s' in '%s' must be declared as 'final'",
                                method.getName(),
                                point.getTarget().getClass().getCanonicalName()
                        )
                );
            }
        }





Aucun commentaire:

Enregistrer un commentaire