GWT 中方法匿名类的问题

发布于 2024-11-07 14:56:32 字数 613 浏览 0 评论 0原文

我正在制作一个类似于 Swing 框架的 GWT 框架。

在 GWT 中,我有一种方法,在方法中创建一个匿名类,但问题是当该方法执行时,执行控制不会转到匿名类,而是会跳过它。

该方法执行完毕后,控制权将转移给匿名类。这个东西在 Swing 中运行得非常好。

public void model(){
    System.out.println("This line is executing");
    DataListModel model = new DataListModel() {
        public void setRecords(List records) {
            System.out.println("I see this line after model() executes completely");
            int i = 0;
            records = new LinkedList(records);
        }
    }
    System.out.println("this line is executed without executing DataListModel.setRecords()");
}   

I am making a GWT framework similar to Swing framework.

In GWT, I have one method in which I am making a anonymous class in method, but the problem is when this method executes, the execution control does not go to anonymous class instead it skips over it.

After this method executes completely, the control is transfered to the anonymous class. And this thing is working perfectly fine in Swing.

public void model(){
    System.out.println("This line is executing");
    DataListModel model = new DataListModel() {
        public void setRecords(List records) {
            System.out.println("I see this line after model() executes completely");
            int i = 0;
            records = new LinkedList(records);
        }
    }
    System.out.println("this line is executed without executing DataListModel.setRecords()");
}   

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福%小乖 2024-11-14 14:56:32

问题在于 DataListModel model = new DataListModel... 行实际上并未执行任何操作。它会创建一个新实例,但除非 DataListModel 构造函数调用 setRecords (它可能不会)或者您在中使用 model 变量以某种方式调用setRecordssetRecords将永远不会被调用。

The problem is that the DataListModel model = new DataListModel... line doesn't actually execute anything. It creates a new instance, but unless either the DataListModel constructor calls setRecords (which it probably doesn't) or you use the model variable in some way that calls setRecords, setRecords will never be called.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文