集册 Java实例教程 获取Getter方法名称

获取Getter方法名称

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

364
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取Getter方法名称
/*
nowjava.com
*/


//package com.nowjava;


public class Main {

    public static void main(String[] argv) throws Exception {

        String property = "nowjava.com";

        System.out.println(getGetterMethodName(property));

    }


    public static String getGetterMethodName(String property) {

        StringBuilder sb = new StringBuilder();


        sb.append(property);

        if (Character.isLowerCase(sb.charAt(0))) {

            if (sb.length() == 1 || !Character.isUpperCase(sb.charAt(1))) {

                sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));

            }

        }

  
展开阅读全文