java - 如何在 JSNI 中使用 GWT $entry 函数?

标签 java javascript html gwt jsni

GWT 中的 $entry 函数用于获取从 JavaScript 向 GWT 报告的未捕获的异常。

以下 $entry 调用之间有什么区别,哪一个是正确的?

以下版本调用实例 Java 函数。

版本 1:

public final native String test(double arg) /*-{
    var instance = this;

    var callExternal = $entry(function(arg) {
       return <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bbd2d5c8cfdad5d8de95fbd8d4d695dec3dad6cbd7de95f6c2f8d7dac8c8" rel="noreferrer noopener nofollow">[email protected]</a>::javaFunction(D)(arg);
    });

    var x = callExternal(arg);
}-*/;

版本 2:

public final native String test(double arg) /*-{
    var x = $entry(<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5c35322f283d323f39721c3f33317239243d312c30397211251f303d2f2f" rel="noreferrer noopener nofollow">[email protected]</a>::javaFunction(D)(arg));
}-*/;

无论使用静态还是非静态 java 函数,用途是否不同?

更新:

以下版本调用静态 Java 函数。

版本 1:

public final native String test(double arg) /*-{

    var callExternal = $entry(function(arg) {
       <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a5d7c0d1d0d7cbe5c6cac88bc0ddc4c8d5c9c08be8dce6c9c4d6d6" rel="noreferrer noopener nofollow">[email protected]</a>::javaFunction(D)(arg);
    });

    var x = callExternal(arg);
}-*/;

版本 2:

public final native String test(double arg) /*-{
    var x = $entry(@com.example.MyClass::staticJavaFunction(D)(arg));
}-*/; 

最佳答案

第二个是错误的:它调用方法然后包装结果。它没用,甚至可能坏了。

$entry 将一个函数包装在另一个使用 try/catch 的函数中。

关于java - 如何在 JSNI 中使用 GWT $entry 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22519254/

相关文章:

java - Android Java,如何将图像从相机传递到 Firebase 存储

javascript - 增加每个输入的名称属性,但在使用 jQuery 克隆后将单选按钮组合在一起

javascript - 如何从 JSONP 语句中选择变量

html - 显示 9x9 div/网格 css

html - 如何在新标签页中打开导航链接 - HTML5

c# - Bentley-Ottmann 算法实现

Java Servlet 404 错误

jquery - 输入点击不起作用

javafx任务错误: NullPointerException

javascript - jQuery 函数在 $(window).resize 之后仍然触发