Monday, November 2, 2015

Re: JsInterop: Casting native javascript objects in gwt

Thank you Gortug for making my aware of the isNative attribute. Unfortunately the cast issue remains.

I have taken the example from the new jsinterop doc, and modified it to illustrate this: https://github.com/bitwerk/jspoc/tree/master/src/main/java/com/acme

// in Java
package com.acme;

@JsType(isNative = true)
interface Foo {
}

@JsType(isNative = true)
class Baz implements Foo{
  public int qux;
}

class Bar {
  @JsMethod
  public static int action(Foo foo) {
    Baz baz = (Baz) foo;
    return baz.qux;
  }
}

// in JavaScript

var baz = { qux: 42 };
com.acme.Bar.action(baz); // will return 42!

The image below demonstrates the issue at runtime.



I can't seem to find anywhere inside the generated javascript, where a class literal is assigned to the value 33.

/Brian

Den torsdag den 29. oktober 2015 kl. 09.37.48 UTC+1 skrev Goktug Gokdogan:
You can only implement java contract (e.g. PayLoad class) in javascript if they are marked as isNative. See the related section in the new jsinterop doc.

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment