如何在一个方法的内部类中使用这个方法的局部变量?
例如
void a()
{
  int x=1;
   class t
   {
      t()
      {
       System.out.print(输出x如何在这里使用 ?)
       }
    }
   ..........}

解决方案 »

  1.   

    static int x = 1。
    这样试试行不行
      

  2.   

    也就是说只能改动局部变量,而没有可以像classname.this这样的调用?
      

  3.   

    public class A{
       public int x = 1;   class t{
          t(){
             System.out.println(A.this.x);
          }
       }
    }
      

  4.   

    晕了~
    public class A
    {
       A()
      {
          x = 1;
          class t{
             t(){
             System.out.println(这里该怎么调用x?);
                }
              }         
      }
    }
      

  5.   

    public class A
    {
    public static int x = 0;
    A()
    {
    class t{
    t(){
    System.out.println(A.x);
    }
    }
    }
    }
      

  6.   

    public class A
    {
       A()
      {
          final int x = 1;//必须定义为final才行
          class t{
             t(){
             System.out.println(这里该怎么调用x?);
                }
              }         
      }
      

  7.   

    也就是说只能改动局部变量,而没有可以像classname.this这样的调用?
    写个程序尝试一下被,不做过谁也不知道结果的!
      

  8.   

    把上面程序修改成完整、可运行的:
    public class AA {
        public int x = 1;    public static void main(String[] args){
           AA aa = new AA();
          
           T tt = aa.new T();
           
        }    class T {
            public T() {
                System.out.println(AA.this.x);
            }
        }
    }
      

  9.   

    狂晕~
    我不是问像这样的调用AA.this.x行不行(可行的)
    而是问假如不更改局部变量x,在内部类中有没有像AA.this.这样的调用外部成员变量的调用?
    final int x = 1;//必须定义为final才行
    这样变成局部常量了,调用时直接System.out.println(x);就可以了
      

  10.   

    算了,我自己给搞糊涂了,忘记了这个最简单的编程常识
    上面那个相当于:
    void x()
    {
       final int a=1;
       void y()
       {   
         System.out.println(a);
        }
    }
    其实本来就该这样 -_-!汗
      

  11.   

    to
    pdvv(我爱花猫) ( ) 信誉:
    你这个不是局部变量~~~