How to handle Double.toString(overlayModel.getSalary()) when "OverlayModel.getSalary()" returns undefined value?

22 views
Skip to first unread message

Alex Luya

unread,
Nov 28, 2011, 4:09:14 AM11/28/11
to google-we...@googlegroups.com
Hi:
Before value hasn't been set into to OverlayModel,if I did:
"Double.toString(overlayModel.getSalary())", a compilation error:""
Something other than a double was returned from JSNI method.....': JS
value of type undefined, expected double" will be thrown out.The
question is why gwt don't return default value(zero ) directly but
"Something" or "JS value of type undefined".How can I hand this
undefined type?
use if(..){} to check?If so,code will be verbose.

Thomas Broyer

unread,
Nov 28, 2011, 6:10:47 AM11/28/11
to google-we...@googlegroups.com
If you want '0' as the "default" value when the property doesn't exist, you can simply define your method as:

public native final double getSalary() /*-{ return this.salary || 0; }-*/;

Reply all
Reply to author
Forward
0 new messages