Java Reflection Method Getter Get getGetterMethodName(String fieldName, java.lang.Class fieldType)

Here you can find the source of getGetterMethodName(String fieldName, java.lang.Class fieldType)

Description

Get the getter method names for attributes.

License

Apache License

Parameter

Parameter Description
fieldName the name of the field
fieldType the type of the field

Return

String the name of the getter method for the field

Declaration

private static <T> String getGetterMethodName(String fieldName, java.lang.Class<T> fieldType) 

Method Source Code

//package com.java2s;
/* Copyright 2010 Google Inc.
 * //from  www  .  j a  va 2  s  .  c  o  m
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS.
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

public class Main {
    /**
     * Get the getter method names for attributes.
     * 
     * @param fieldName the name of the field
     * @param fieldType the type of the field
     * @return String the name of the getter method for the field
     */
    private static <T> String getGetterMethodName(String fieldName, java.lang.Class<T> fieldType) {

        String firstStringChar = fieldName.substring(0, 1).toUpperCase();
        String remaingString = fieldName.substring(1);

        String methodName = null;
        /* In case the the field is a boolean */
        if (fieldType != null && fieldType == boolean.class || fieldType == Boolean.class) {

            methodName = "is" + firstStringChar + remaingString;
        } else {
            methodName = "get" + firstStringChar + remaingString;
        }
        return methodName;
    }
}

Related

  1. getGetterMethod(Class clazz, String name)
  2. getGetterMethod(Class clazz, String propertyName)
  3. getGetterMethod(String getterName, Object bean, Class returnType)
  4. getGetterMethodByProperty(String propertyName, Class beanClass, Class returnType)
  5. getGetterMethodForClass(Class cls, String beanName)
  6. getGetterMethodName(String property, String javaType)
  7. getGetterMethodNames(Object o)
  8. getGetterMethods(Class clazz)
  9. getGetterMethods(Class clazz)