Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to find if a Field is boolean the same as isPrimitive()?

Is there a way to find if a Field is boolean in Java reflection the same as isPrimitive()?

Field fieldlist[] = clazz.getDeclaredFields();
for (int i = 0; fieldlist.length & gt; i; i++) {
 Field fld = fieldlist[i];
 if (fld.getClass().isPrimitive()) {
  fld.setInt(object, 0);
  continue;
 }
}
like image 737
nabil Avatar asked Jan 14 '12 18:01

nabil


1 Answers

if(fld.getType().equals(boolean.class))

Just tested this and it works for primitive boolean variables.

like image 169
Tudor Avatar answered Oct 04 '22 16:10

Tudor