android - Java generic type for objects -
in objective-c have generic type objects called "id".
id someobject = somevalue; if([someobject iskindofclass:[nsstring class]]) { nsstring *string = someobject; }
i want know if there's in java.
id someobject = somevalue; if(someobject instanceof string) { string string = someobject; }
unless i'm missing something, close answer yourself:
// obtain object somewhere object someobject = obtainobjectinstance(); // if it's string... if(someobject instanceof string) { // cast , assign variable string string = (string)someobject; }
as side note, object instances contain information object's class: someobject.getclass()
Comments
Post a Comment