java - The equivalent of instanceof -


what equivalent of without using instanceof? maybe more simple while using true, false or else statements?

public static void p (object...ar) {         (int i=0; < ar.length; i++)         {                 if (ar[i] instanceof int[])                 { 

for primitive arrays can, instead of:

if (ar[i] instanceof int[]) 

use:

if (ar[i].getclass() == int[].class) 



note: above code works fine arrays of primitive types. please aware, though, instanceof checks if object in left-part subtype of class in right-part, while == not.
objects, equivalent (myinstance instanceof myclass[]) (checks subtyping) is:

(   myclass[].class.isassignablefrom(  myinstance.getclass()  )   ) 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -