java - Simplest way to retrieve an int from a mongo result? -


i'm pulling int mongo cursor object so:

dbobject mapobj = cursor.next(); int autostart = (int) (double) (double) mapobj.get("autostart"); 

it seems strange have triple cast integer, there better way?

i think looking this:

dbobject mapobj = cursor.next(); int autostart = ((number) mapobj.get("autostart")).intvalue(); 

no conversion string , safe if value gets converted double or long (with potential loss of precision) original integer value. double, long , integer extend number.

hth rob


Comments

Popular posts from this blog

Capture and play voice with Asterisk ARI -

c++ - Can not find the "fiostream.h" file -

java - Why database contraints in HSQLDB are only checked during a commit when using transactions in Hibernate? -