getDeclaredField()方法的结果是什么?

时间:2017-04-10 08:56:14

标签: java

以下代码中getDeclaredField方法的功能是什么? tempClazz没有在代码中的任何地方定义。任何人都可以帮助理解下面的代码吗?

private static Field getDeclaredField(Class tempClazz, String fieldName) {
    Field field = null;
    try {
        field = tempClazz.getDeclaredField(fieldName);
        field.setAccessible(true);
    } catch (SecurityException e) {
        return field;
    } catch (NoSuchFieldException e) {
        tempClazz = tempClazz.getSuperclass();
        if (tempClazz == null) {
            throw new RuntimeException(e);
        }
        field = getDeclaredField(tempClazz, fieldName);
        return field;
    }
    return field;
}

1 个答案:

答案 0 :(得分:0)

当然是:

private static Field getDeclaredField(Class tempClazz

这是该方法的参数!

对于该方法的含义:只需研究其javadoc

  

返回一个Field对象,该对象反映此Class对象所表示的类或接口的指定声明字段。 name参数是一个String,它指定所需字段的简单名称。

相关问题