java - Getting instance of object? -


i have slight problem. wrote function should generate table list of objects (it date or custom 1 or whichever). parametars of function "list list" , "list headings". so, here question, why line

if (value.getclass().isinstance(date.class) ... 

not executing, thou when print value.getclass() says the: class java.util.date. question, how check if "value" list? lot in advance :)

here part of code:

for (object o : list) {      list<string> atributes = new arraylist<string>();      (java.lang.reflect.field field :o.getclass().getdeclaredfields()) {          field.setaccessible(true);         object value = field.get(o);         if (value != null) {             if (value.getclass().isinstance(date.class)) {                 atributes.add(convertdatetostring((java.util.date) value));             }             atributes.add(value.tostring());         }         } ... 

you're misusing class#isinstance, returns true if date.class instance of value.getclass():

determines if specified object assignment-compatible object represented class. method dynamic equivalent of java language instanceof operator. method returns true if specified object argument non-null , can cast reference type represented class object without raising classcastexception. returns false otherwise.

rather, want either:

if(value instanceof date) 

or

if(date.class.isinstance(value)) 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -