Google Web Toolkit’s (GWT) Fake Long
February 24, 2008
I ran into a cunning Google Web Toolkit JavaScript problem, related to the Java long data type. I was using long for my objects’ identities, that are persisted to db4o. On the server side the objects’ identities had the correct values. When I returned the object as a serialized XML string, the value was also correct. But as soon as I tried to directly use long, the value was always one less, than the actual value it was meant to be.
Before I decided on long for my object identities, I had a gut feeling that JavaScript might not support this data type. Turns out my original suspicion was valid: “Intrinsic types byte, char, short, int, long, float, double, Object, String, and
arrays are supported. However, there is no 64-bit integral type in JavaScript, so variables of type long are mapped onto JavaScript double-precision floating point values. To ensure maximum consistency between hosted mode and web mode, we recommend that you use int variables.”
It probably would be a good idea if the GWT compiler reported any long types as warnings. There’s no point having a long that doesn’t really work. It just opens the opportunity for problems like this one.






February 28, 2008 at 2:09 am
Any chance you can contribute your app (or a sample) to projects.db4o.com?
Best!
German
March 5, 2008 at 6:02 pm
This is definitely planned. I’d like to flesh the project out a little bit more, before making it public. But I promise as soon as some key features have been completed, GhostBlade will be at projects.db4o.com!
January 4, 2009 at 2:55 am
Nice thanks! You can reach me at german -AT – db4o.com
Best regards!!
German