Return true if method matches naming convention for mutator. - Java Reflection

Java examples for Reflection:Method Return

Description

Return true if method matches naming convention for mutator.

Demo Code


//package com.java2s;
import java.lang.reflect.Method;

public class Main {
    /** Prefix for all mutator methods. */
    private static final String MUTATOR_PREFIX = "set";

    /**// w  w  w. j  a v  a  2s  .c  o m
     * Return true if method matches naming convention for mutator.
     *
     * @param method the method.
     * @return true if method matches naming convention for mutator.
     */
    public static boolean isMutator(final Method method) {
        final String name = method.getName();
        return name.startsWith(MUTATOR_PREFIX) && name.length() > 3
                && Void.TYPE == method.getGenericReturnType()
                && method.getParameterTypes().length == 1;
    }
}

Related Tutorials