I have a list of BasicDBObject that I fetch from my database. This is basically a JSON document converted into a java Object.
Let's assume that we have a BasicDBObject named result
This JSON document may or may not contain the key name. If the document doesn't contain the key, result.get("name") will return null.
Is there a difference in terms of performance between this :
BasicDBObject result = ...
Object name = result.get("name");
String nameString = (name == null ? "." : name.toString());
and
BasicDBObject result = ...
String name = (String) result.get("name");
String nameString = (name == null ? "." : name);
Even if this part of the code is called 100 000+ times within a function, I know this wil never be the bottleneck, I'm just interested in the answer.
Kittenor something weird like that, it'll just print a stringified version of it usingObject#toString(). This may or may not be what you want. \$\endgroup\$