Retrieves a setter name based on a field name passed in - Java Reflection

Java examples for Reflection:Setter

Description

Retrieves a setter name based on a field name passed in

Demo Code


//package com.java2s;

public class Main {


    /**//from w ww. j a  v a2 s  . c om
     * Retrieves a setter name based on a field name passed in
     *
     * @param fieldName field name to find setter for
     * @return name of setter method
     */
    public static String fluentSetterName(String fieldName) {
        StringBuilder sb = new StringBuilder();
        if (fieldName != null && fieldName.length() > 0) {
            sb.append(fieldName.substring(0, 1));
            if (fieldName.length() > 1) {
                sb.append(fieldName.substring(1));
            }
        }
        return sb.toString();
    }
}

Related Tutorials