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

前端 未结 4 1274
北恋
北恋 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:48

    field.get(target) returns Object. So you can checkif (field.get(this) == null) {..}

    If the field is primitive, it will get wrapped. int -> Integer, char -> Character, etc.

提交回复
热议问题