Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.lang.reflect.Field;

public class Main {
    public static Class<?> sCurrentClass;

    public final static int getStaticIntValue(String name, int defvalue) {
        int result = defvalue;
        Field field = getField(name);

        if (field != null) {
            try {
                result = field.getInt(null);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return result;
    }

    private final static Field getField(String name) {
        Field field = null;
        try {
            field = sCurrentClass.getDeclaredField(name);
            field.setAccessible(true);
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            //         e.printStackTrace();
        }

        return field;
    }
}