<small id='YxR1f'></small><noframes id='YxR1f'>

    1. <legend id='YxR1f'><style id='YxR1f'><dir id='YxR1f'><q id='YxR1f'></q></dir></style></legend>

    2. <i id='YxR1f'><tr id='YxR1f'><dt id='YxR1f'><q id='YxR1f'><span id='YxR1f'><b id='YxR1f'><form id='YxR1f'><ins id='YxR1f'></ins><ul id='YxR1f'></ul><sub id='YxR1f'></sub></form><legend id='YxR1f'></legend><bdo id='YxR1f'><pre id='YxR1f'><center id='YxR1f'></center></pre></bdo></b><th id='YxR1f'></th></span></q></dt></tr></i><div id='YxR1f'><tfoot id='YxR1f'></tfoot><dl id='YxR1f'><fieldset id='YxR1f'></fieldset></dl></div>

    3. <tfoot id='YxR1f'></tfoot>
        <bdo id='YxR1f'></bdo><ul id='YxR1f'></ul>

      从异步调用运行方法返回一个值

      Return a value from asynchronous call to run method(从异步调用运行方法返回一个值)
      <tfoot id='sZoHJ'></tfoot>

        <tbody id='sZoHJ'></tbody>

      <i id='sZoHJ'><tr id='sZoHJ'><dt id='sZoHJ'><q id='sZoHJ'><span id='sZoHJ'><b id='sZoHJ'><form id='sZoHJ'><ins id='sZoHJ'></ins><ul id='sZoHJ'></ul><sub id='sZoHJ'></sub></form><legend id='sZoHJ'></legend><bdo id='sZoHJ'><pre id='sZoHJ'><center id='sZoHJ'></center></pre></bdo></b><th id='sZoHJ'></th></span></q></dt></tr></i><div id='sZoHJ'><tfoot id='sZoHJ'></tfoot><dl id='sZoHJ'><fieldset id='sZoHJ'></fieldset></dl></div>

          <small id='sZoHJ'></small><noframes id='sZoHJ'>

          • <bdo id='sZoHJ'></bdo><ul id='sZoHJ'></ul>
          • <legend id='sZoHJ'><style id='sZoHJ'><dir id='sZoHJ'><q id='sZoHJ'></q></dir></style></legend>

                本文介绍了从异步调用运行方法返回一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个必须返回布尔值的方法.该方法有一个异步调用 run 方法.在运行方法中,我必须在封闭方法中设置变量.下面是我的代码.

                I have a method that has to return a boolean value. The method has an asynchronous call to run method. In the run method, i have to set variable in the enclosing method. below is my code.

                private boolean isTrue() {
                    boolean userAnswer;
                    Display.getDefault().asyncExec(new Runnable() {
                        public void run() {
                            userAnswer = MessageDialog.openQuestion(new Shell(), "some message", "some question?");
                        }
                    });
                    return userAnswer;
                }   
                

                这段代码给出了错误——userAnswer"必须是最终的,如果我把它变成最终的,我就不能给它赋值.请提出一种处理这种情况的方法.

                This code gives error -- "userAnswer" has to be final, and if i make it final i cant assign a value to it. Please suggest a way to handle this scenario.

                推荐答案

                如果需要适配一个Callable,可以使用java.util.concurrent.FutureTask; 到一个 Runnable.

                public class UserQuestion implements Callable<Boolean> {
                
                    private String message;
                    private String question;
                
                    public UserQuestion(String message, String question) {
                        this.message = message;
                        this.question = question;
                    }
                
                    public Boolean call() throws Exception {
                        boolean userAnswer = MessageDialog.openQuestion(new Shell(),
                                message, question);
                        return Boolean.valueOf(userAnswer);
                
                    }
                }
                
                UserQuestion userQuestion = new UserQuestion("some message", "some question?");
                FutureTask<Boolean> futureUserAnswer = new FutureTask<Boolean>(userQuestion);
                Display.getDefault().asyncExec(futureUserAnswer);
                Boolean userAnswer = futureUserAnswer.get();
                

                这篇关于从异步调用运行方法返回一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                  <legend id='T5gmO'><style id='T5gmO'><dir id='T5gmO'><q id='T5gmO'></q></dir></style></legend>

                      <bdo id='T5gmO'></bdo><ul id='T5gmO'></ul>
                      • <i id='T5gmO'><tr id='T5gmO'><dt id='T5gmO'><q id='T5gmO'><span id='T5gmO'><b id='T5gmO'><form id='T5gmO'><ins id='T5gmO'></ins><ul id='T5gmO'></ul><sub id='T5gmO'></sub></form><legend id='T5gmO'></legend><bdo id='T5gmO'><pre id='T5gmO'><center id='T5gmO'></center></pre></bdo></b><th id='T5gmO'></th></span></q></dt></tr></i><div id='T5gmO'><tfoot id='T5gmO'></tfoot><dl id='T5gmO'><fieldset id='T5gmO'></fieldset></dl></div>

                          <tfoot id='T5gmO'></tfoot>

                            <tbody id='T5gmO'></tbody>

                          <small id='T5gmO'></small><noframes id='T5gmO'>