java objects
How can i tell what type an object is. For example
public Object returnObject() { return randomObject; } How can i tell what object type it is. |
One way is by using <objectName>.getClass().getName(). I'll continue searching, though, for other info I can find.
|
If you are writing the code then you should know what kind of an object it is. Otherwise, its very hard to tell because it could be an object from one of the data types in java or an object of some class that someone wrote. For example, a class can be something like:
Code:
|
are you truly returning any object type? cause if it is a limited set of objects you could possibly return, you could always validate your objects using instanceof
Code:
if (objecta instanceof dud) Code:
if(Class.forname("dud").isInstance(objecta)) |
All times are GMT -5. The time now is 08:33 PM. |