I couldn't reproduce the IntParser problem with following test:

  @JsType(namespace = JsPackage.GLOBAL)
  public static class IntParser {
    public static int parseArray(String[] args) {
      return Integer.parseInt(args[0]);
    }
  }

  public void testStringArray() {
    assertEquals(42, callIntParser());
  }

  private native int callIntParser() /*-{
    return $wnd.IntParser.parseArray(["42"]);
  }-*/;

​

Also in your earlier example, you are casting { qux: 42 } to Baz which will 
fail because ({ qux: 42 } instanceof com.acme.Baz) is not true as { } is 
instance of global Object. You can change Baz to point to that:

@JsType(isNative = true, name="Object", namespace=GLOBAL)
class Baz implements Foo {
  public int qux;
}


On Wednesday, November 4, 2015 at 11:18:05 PM UTC-8, Brian Pedersen wrote:
>
> Thanks.
>
> If it is any help, my code is here: 
> https://github.com/bitwerk/jspoc/tree/master/src/main/java/com/acme
>
> /Brian
>
> Den torsdag den 5. november 2015 kl. 06.41.35 UTC+1 skrev Goktug Gokdogan:
>>
>> This should work. I need to take a look why it fails.
>>
>>
>> On Wednesday, November 4, 2015 at 3:04:11 AM UTC-8, Brian Pedersen wrote:
>>>
>>> Here is another variant, failing with the same exception
>>>
>>> //In Java
>>> package com.acme;
>>>
>>> @JsType
>>> public class IntParser {
>>>   public static int parseArray(String[] args) {
>>>     return Integer.parseInt(args[0]);
>>>   }
>>> }
>>>
>>> //In Javascript
>>> var num = com.acme.IntParser.parseArray(["42"]); // Should return 42, 
>>> but throws 'Uncaught [object Object]'!
>>>
>>>
>>>
>>> Den mandag den 2. november 2015 kl. 11.11.35 UTC+1 skrev Brian Pedersen:
>>>>
>>>> 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.
>>>>
>>>>
>>>> <https://lh3.googleusercontent.com/-9z2t_Q8R0oI/Vjc1qBoQgfI/AAAAAAAABEc/CAbDBqNfUZc/s1600/debugger3.png>
>>>>
>>>>
>>>> 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+unsubscr...@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.

Reply via email to