简体   繁体   English

如何从类内部引用非最终变量“out”?

[英]How to refer to non final variable “out” from inside class?

I have seen questions related to the topic, but i couldn't find a satisfactory answer. 我已经看到了与该主题相关的问题,但我找不到满意的答案。 Please help me with my JSP code: 请帮助我使用我的JSP代码:

 <%
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        Future<Integer> f = asyncHttpClient.prepareGet("http://www.ning.com/")
          .execute(new AsyncCompletionHandler<Integer>(){

        public STATE onStatusReceived(HttpResponseStatus respstat)throws Exception{
                    ***//error occurs in next line***
            out.println(respstat.getStatusText());
            return STATE.CONTINUE;
        }
        @Override
        public Integer onCompleted(Response response) throws Exception{
            // Do something with the Response
            out.println(response.getStatusCode());
            return response.getStatusCode();
        }

        @Override
        public void onThrowable(Throwable t){
            // Something wrong happened.
        }
    });
  %>

since out is a jsp variable, i cant define it as a final as well. 因为out是一个jsp变量,所以我也不能将它定义为final。 What do i do in this case? 在这种情况下我该怎么办?

Thanks 谢谢

<%
        final ServletOutputStream finalOut = out; // create final reference

        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        Future<Integer> f = asyncHttpClient.prepareGet("http://www.ning.com/")
          .execute(new AsyncCompletionHandler<Integer>(){

        public STATE onStatusReceived(HttpResponseStatus respstat)throws Exception{
                    ***//error occurs in next line***
            finalOut.println(respstat.getStatusText());  //use final reference
            return STATE.CONTINUE;
        }
        @Override
        public Integer onCompleted(Response response) throws Exception{
            // Do something with the Response
            out.println(response.getStatusCode());
            return response.getStatusCode();
        }

        @Override
        public void onThrowable(Throwable t){
            // Something wrong happened.
        }
    });
  %>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 不能在内部类中引用非最终变量 - Cannot refer to non-final variable inside an inner class 不能在不同方法中定义的内部类中引用非final变量str - 如何解决这个问题? - Cannot refer to a non-final variable str inside an inner class defined in a different method - How to fix this? 绕过&#39;无法引用定义的内部类中的非final变量&#39; - Bypassing 'Cannot refer to a non-final variable inside an inner class defined' 出现错误“无法在用其他方法定义的内部类中引用非最终变量” - Getting error “Cannot refer to a non-final variable inside an inner class defined in a different method” 类型无法引用用其他方法定义的内部类中的非最终变量Asortiment - Type Cannot refer to a non-final variable Asortiment inside an inner class defined in a different method “不能引用在不同方法中定义的内部类中的非最终变量buttonflag” - “Cannot refer to a non-final variable buttonflag inside an inner class defined in a different method” 不能在不同方法中定义的内部类中引用非最终变量 - Cannot refer to a non-final variable inside an inner class defined in a different method 不能在不同方法中定义的内部类中引用非final变量i - Cannot refer to a non-final variable i inside an inner class defined in a different method 无法以不同方法定义的内部类中引用非最终变量LinearLayout - Cannot refer to a non-final variable LinearLayout inside an inner class defined in a different method 无法在使用其他方法定义的内部类中引用非最终变量pcurl1 - Cannot refer to a non-final variable pcurl1 inside an inner class defined in a different method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM