I do not think much, so this question may be obvious. E.g. I have a class:
public class Document { private String someStr; private byte[] contents;
I am trying to check if the contents field is an instance of a byte array. What I tried:
Class clazz = Document.class; Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { if (field.getType().isArray()) { Object array = field.getType(); System.out.println(array); } }
The output of this code is class [B I see that an array of bytes is found, but if I do:
if (array instanceof byte[]) {...}
This condition is never true . Why is this? And how to check if an object contains fields of type byte[] ?
Paulius matulionis
source share