2011-11-22 46 views

回答

8

field.get(target)返回Object。所以你可以檢查if (field.get(this) == null) {..}

如果該字段是原始的,它將被包裝。 int - >Integerchar - >Character

3

您需要從對象獲取的字段,則檢查其是否爲空

Field f = this.getClass().getFields()[0]; 
if (f.get(this) == null) 
    ... 
+0

,如果它有一種原始的東西類型? – shift66

+0

它會被包裹 – Bozho

0

使用Object obj=f.get(this)和檢查返回的對象(在這種情況下OBJ)是否爲空或不是

相關問題