Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.lang.reflect.Method;

public class Main {
    private static Method findGetterMethod(String propertyName, Class<?> itemClass) {
        try {
            String capitalizedPropertyName = capitalize(propertyName);
            Method getterMethod;
            try {
                getterMethod = itemClass.getMethod("get" + capitalizedPropertyName);
            } catch (NoSuchMethodException e) {
                getterMethod = itemClass.getMethod("is" + capitalizedPropertyName);
            }
            return getterMethod;
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException("Could not find getter method for property " + propertyName);
        }
    }

    private static String capitalize(String original) {
        if (original.isEmpty()) {
            return original;
        }
        StringBuilder sb = new StringBuilder();
        sb.append(original.substring(0, 1).toUpperCase());
        sb.append(original.substring(1));
        return sb.toString();
    }
}