I get an object and need to register it. Some of them have cusom toString(), and then I would like to use this, but some do not, and I get something like mightypork.rogue.bus.events.MouseMotionEvent@2d19587d.
I'm looking for a way to dynamically (perhaps with reflection?) Verify that the incoming object is toString()redefined itself.
String objToString(Object o)
{
if(???) {
return o.toString();
} else {
return o.getClass().getSimpleName();
}
}
Side note:
This is an event bus system, some classes can subscribe and then receive events based on implemented interfaces. I cannot require all clients to have toString (), plus I want to use this method for more than one purpose.
source
share