How to test whether the value of a Java field gotten by reflection is null?

前端 未结 4 1302
北恋
北恋 2021-01-15 16:42

I have

Field f = this.getClass().getFields()[0];

I need to know if f\'s value in this is null or not

4条回答
  •  深忆病人
    2021-01-15 16:55

    You didn't search well enough: http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Field.html#get%28java.lang.Object%29

    Call this method, and check if the returned object is null.

提交回复
热议问题