久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <tfoot id='SnhJ0'></tfoot>

    <legend id='SnhJ0'><style id='SnhJ0'><dir id='SnhJ0'><q id='SnhJ0'></q></dir></style></legend>
      <bdo id='SnhJ0'></bdo><ul id='SnhJ0'></ul>
    1. <i id='SnhJ0'><tr id='SnhJ0'><dt id='SnhJ0'><q id='SnhJ0'><span id='SnhJ0'><b id='SnhJ0'><form id='SnhJ0'><ins id='SnhJ0'></ins><ul id='SnhJ0'></ul><sub id='SnhJ0'></sub></form><legend id='SnhJ0'></legend><bdo id='SnhJ0'><pre id='SnhJ0'><center id='SnhJ0'></center></pre></bdo></b><th id='SnhJ0'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='SnhJ0'><tfoot id='SnhJ0'></tfoot><dl id='SnhJ0'><fieldset id='SnhJ0'></fieldset></dl></div>

      1. <small id='SnhJ0'></small><noframes id='SnhJ0'>

        訪問java內部類中的變量

        access to variable within inner class in java(訪問java內部類中的變量)

            <tbody id='lcFHb'></tbody>

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

                <bdo id='lcFHb'></bdo><ul id='lcFHb'></ul>

                <legend id='lcFHb'><style id='lcFHb'><dir id='lcFHb'><q id='lcFHb'></q></dir></style></legend>
              • <i id='lcFHb'><tr id='lcFHb'><dt id='lcFHb'><q id='lcFHb'><span id='lcFHb'><b id='lcFHb'><form id='lcFHb'><ins id='lcFHb'></ins><ul id='lcFHb'></ul><sub id='lcFHb'></sub></form><legend id='lcFHb'></legend><bdo id='lcFHb'><pre id='lcFHb'><center id='lcFHb'></center></pre></bdo></b><th id='lcFHb'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='lcFHb'><tfoot id='lcFHb'></tfoot><dl id='lcFHb'><fieldset id='lcFHb'></fieldset></dl></div>
                <tfoot id='lcFHb'></tfoot>
                • 本文介紹了訪問java內部類中的變量的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試創建一個 JLabels 數組,單擊時它們都應該不可見.當試圖通過需要訪問用于聲明標簽的循環的迭代變量的內部類來設置鼠標偵聽器時,就會出現問題.代碼不言自明:

                  I'm trying to create an array of JLabels, all of them should go invisible when clicked. The problem comes when trying to set up the mouse listener through an inner class that needs access to the iteration variable of the loop used to declare the labels. Code is self-explanatory:

                      for(int i=1; i<label.length; i++) {
                         label[i] = new JLabel("label " + i);
                         label[i].addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent me) {
                               label[i].setVisible(false);   // compilation error here
                            }
                         });
                         cpane.add(label[i]);
                      }
                  

                  我認為我可以通過使用 this 或者 super 而不是調用 label[i] 來克服這個問題內部方法,但我一直無法弄清楚.

                  I thought that I could overcome this by the use of this or maybe super instead of the call of label[i] within the inner method but I haven't been able to figure it out.

                  編譯錯誤是:局部變量i是從內部類中訪問的;需要聲明為final`

                  The compilation error is: local variable i is accessed from within inner class; needs to be declared final`

                  我確定答案一定是我沒有想到的非常愚蠢的事情,或者我犯了一些小錯誤.

                  I'm sure that the answer must be something really silly I haven't thought of or maybe I'm making some small mistake.

                  任何幫助將不勝感激

                  推薦答案

                  您的局部變量必須是 final 才能從內部(和匿名)類訪問.

                  Your local variable must be final to be accessed from the inner (and anonymous) class.

                  您可以將代碼更改為以下內容:

                  You can change your code for something like this :

                  for (int i = 1; i < label.length; i++) {
                      final JLabel currentLabel =new JLabel("label " + i); 
                      currentLabel.addMouseListener(new MouseAdapter() {
                          public void mouseClicked(MouseEvent me) {
                              currentLabel.setVisible(false);   // No more compilation error here
                          }
                      });
                      label[i] = currentLabel;
                  }
                  

                  來自 JLS:

                  任何使用但未在內部類中聲明的局部變量、形參或異常參數都必須聲明為final.

                  Any local variable, formal parameter, or exception parameter used but not declared in an inner class must be declared final.

                  任何使用但未在內部類中聲明的局部變量必須明確分配 (§16) 在內部類的主體之前.

                  Any local variable used but not declared in an inner class must be definitely assigned (§16) before the body of the inner class.

                  <小時>

                  資源:

                  • JLS - 內部類和封閉實例

                  這篇關于訪問java內部類中的變量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)

                    <tfoot id='4jaq5'></tfoot>

                      <tbody id='4jaq5'></tbody>
                  • <legend id='4jaq5'><style id='4jaq5'><dir id='4jaq5'><q id='4jaq5'></q></dir></style></legend>

                          <small id='4jaq5'></small><noframes id='4jaq5'>

                          • <bdo id='4jaq5'></bdo><ul id='4jaq5'></ul>
                            <i id='4jaq5'><tr id='4jaq5'><dt id='4jaq5'><q id='4jaq5'><span id='4jaq5'><b id='4jaq5'><form id='4jaq5'><ins id='4jaq5'></ins><ul id='4jaq5'></ul><sub id='4jaq5'></sub></form><legend id='4jaq5'></legend><bdo id='4jaq5'><pre id='4jaq5'><center id='4jaq5'></center></pre></bdo></b><th id='4jaq5'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4jaq5'><tfoot id='4jaq5'></tfoot><dl id='4jaq5'><fieldset id='4jaq5'></fieldset></dl></div>
                            主站蜘蛛池模板: 免费的一级片 | 欧美精品一区二区在线观看 | 免费av片 | 成人免费毛片嘿嘿连载视频 | 亚洲国产成人在线 | av女人的天堂 | 国产小精品 | www精品| 久草资源在线 | 欧美精品日韩少妇 | 精品黄色片 | 成人免费片 | 亚洲黄色网址 | 精品国产99久久久久久宅男i | 男人午夜视频 | 亚洲激情久久 | 成人激情综合网 | 一级片在线视频 | 亚洲国产第一页 | 精品亚洲一区二区三区四区五区 | 黄视频免费看网站 | 黄色精品网站 | 日本乱子伦 | 天天插夜夜操 | 在线日韩视频 | 国产精品剧情 | 国产精品成人免费视频 | 一区二区久久久 | 91久久久久久久久久 | 久婷婷| 日韩精品成人 | 在线观看一区 | 国产日韩中文字幕 | 精品久久网站 | 手机av在线播放 | 午夜视频在线看 | 久久精品6| 青青草原国产 | 97精品在线观看 | 午夜精品福利视频 | 久久精品国产视频 |