集册 Java实例教程 如果方法与mutator的命名约定匹配,则返回true。

如果方法与mutator的命名约定匹配,则返回true。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

466
如果方法与mutator的命名约定匹配,则返回true。
/* 来自 时 代 J a v a - nowjava.com*/

//package com.nowjava;

import java.lang.reflect.Method;


public class Main {

    /** Prefix for all mutator methods. */

    private static final String MUTATOR_PREFIX = "set";


    /**

     * 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.getGeneri
展开阅读全文