-
Notifications
You must be signed in to change notification settings - Fork 370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relax JsInteorp restriction checking so one can perform feature check #9327
Comments
Null primitives is quite annoying I hope GWT team will find good solution (manolo already makes a comment in the NextGen doc, and you said that Double and now Boolean can be used) but... Other more weird idea: // field is substitude by the field name, this is useful to save the string as a constant
@JsProperty(getter=“$field++”) int increment();
// using a constant
@JsProperty(getter=INCREMENT) int increment();
// even more weird example (not sure if this makes sense)
@JsProperty(
getter=“var l=@java.util.ArrayList::new()();l.@java.util.ArrayList::array=$field;return l;”,
setter=“$field = $set.@java.util.ArrayList::array”
) ArrayList<String> tokens();
// using a constant
@JsProperty(getter=ARRAY_LIST_GET, setter=ARRAY_LIST_SET) ArrayList<String> tokens();
// and just because is so easy to say thing a do not implement them...
@JsProperty(getter=ARRAY_LIST_GET, setter=ARRAY_LIST_SET)
@Target(FIELD) @Retention(RUNTIME) @JsDef
public @interface JsList {}
// so can be used as javax.validation annotation composition, just to clean up the code
@JsList ArrayList<String> tokens(); |
In general JsInterop v1 tries to be close to original JavaScript and avoids features that modifies the underlying abstraction heavily. The future plan to do abstraction modifications is via @JsConvert which will basically let you run the object through a function supplied by you. |
Mmm... but... a JsInterop which returns a null primitive java value might be discutible as something that will be solved in v2. At least some module property which allow you to add the minimal safety to use primitive which behaves like java primitives, so primitives getter will be written as (val || def) where def is the default java value for the java primitive. I'll try to stop commenting, and I will try to try it myself 😉, thanks anyways. |
@ignacio, I think you misread the point. This is not about primitive types. On Wed, May 4, 2016 at 11:48 PM, Ignacio Baca Moreno-Torres <
|
To answer your last comment; |
@rluble yep, I know this is not about primitives, probably not the best place to solve my doubts. But, if primitives can be safety defaulted to a java-primitive-default-value, this use case (double now()) will returns 0, so the second method to check if is null won't be necessary (maybe this isn't good). So I took the opportunity to comment my null-primitive concerns. Looks like @gkdn are seeing this more in the side of JS, and I'm more in the side of Java. But you said; "you can only use java primitives for convenience if you don't have any concerns of nullability" so.. why are you using it in this now() method? 😞 My actual use case is for shared DTOs. @JsType(isNative=true,namespace=GLOBAL,name="Object") class MyDto {
public int foo;
public int bar;
} And my concerns are that the client instance will have null foo/bar but server instances will not (need to be native and "Object" because this can come from a JSON). Just curious in the actual motivation on admit null-primitives. But as @gkdn said, v1 tries to be close to the original JavaScript. So I'm ok. Thanks! |
window.performance.now can never return null. window.performance.now not being existent is different that now returning null when you 'call' it. |
A native property is allowed to have the same name as a native method. A property is considered native if both setter and getter are native if they exist. Bug: gwtproject#9327 Bug-Link: http://github.com/gwtproject/gwt/issues/9327 Change-Id: I047fae52e344453eb1222c5a8e594f5f4cf53bff
Relax JsInteorp restriction checking so one can perform feature check; like:
Above snippet fails due to name restriction checking.
Current workaround:
The text was updated successfully, but these errors were encountered: