ArrayList tList=new ArrayList();
byte[] Data=null;
tList.Add(Data);
if(tList.get(0) instanceof byte[]){} else if(tList.get(0) == null){}
byte[] Data=null;
tList.Add(Data);
if(tList.get(0) instanceof byte[]){} else if(tList.get(0) == null){}
另外可以用isArray和getClass().getComponentType来判断。
Demo 如下:public class RtType {
byte[] bts = new byte[]{0,1,2}; public void testType(Object objs){
System.out.println("instanceof byte[]?"+(objs instanceof byte[]));
System.out.println("isArray?"+objs.getClass().isArray());
if (objs.getClass().isArray()){
System.out.println("getClass.getComponentType:"+objs.getClass().getComponentType());
}
}
public static void main(String[] args) {
RtType rt = new RtType();
rt.testType(rt.bts);
}
}