随便写几句,就是如果把里边的如storeLocation这些东东传出去??
(new Thread(){
public void run()
{
statics = new Integer[256];
for(int i=0;i<256;i++)
{
statics[i]=0;
} for(int i=0;i<256;i++)
{
if(max < statics[i])
{
max = statics[i];
   storeLocation = i;
}
}
}
}).start();

解决方案 »

  1.   

    storeLocation  在哪里声明的?我怎么没看到?呵呵呵!
      

  2.   

    给你举个例子package a;public class A {

    public static void main(String args[]) {
    System.out.println(new I(){
    private int i=1;
    public void foo(){}
    public int getI(){return i;}
    }.getI());
    }
    }interface I{
    void foo();
    }
    这种内部类很大程度上是为了书写方便,或者是为了更好的封装,体现逻辑结构。
    如果你又要让你的 thread start,又要返回其他的值,这种复杂的时候就不要考虑用内部类了
      

  3.   

    不知道要到哪? 和final应该关系不大哟
      

  4.   

    用容器类就行了。final List al = new ArrayList();
    传给内部类,你在内部类中往里加元素。外部就能得到。或者直接声明一个元素的数组来代替你要声明的变量。比如原来你想声明一个Date变量,在内部类中想改变它,但因为final的原因你不能改变,你可以:final Date[] d = new Date[1];
    d[0] = new Date();然后你在外部或内部类中用d[0]来代表要传入的Date,你就可以任意修改。
      

  5.   

    可以利用jdk5.0的
    Callable接口和Future接口 就可以简单实现你那个功能(new ExecutorService().submint(new Callable({
                public Object call() throws Exception
                {
                    statics = new Integer[256];        
                    for(int i=0;i<256;i++)
                    {
                        statics[i]=0;
                    }                for(int i=0;i<256;i++)
                    {
                        if(max < statics[i])
                        {
                            max = statics[i];
                           storeLocation = i;
                        }
                    }
                    return storeLocation;
                }
            }));
            //返回的是Future值
            //通过Future.get() 就可以简单的得到线程返回的Object
      

  6.   


    public class Test 

          public static void main(String[] args) 
          { 
           final int account[]=new int[1];
           System.out.println("之前:"+account[0]);
           new ClassTest(){
           public void addLocalVaribal(){
           account[0]++;
           }
           }.addLocalVaribal();
           System.out.println("之后:"+account[0]);
          } 

    class ClassTest{

    }LZ看看是不是这种效果,利用数组解决。
      

  7.   

    public class Test {
    public static void main(String[] args) {
    TT tt = new Test().new TT();
    System.out.println(tt.getX());
    }

    class TT {
    final int x=0;
    int getX() {return x;}
    }
    }
      

  8.   


    (new Thread(){
                public void run()
                {
                    statics = new Integer[256];        
                    for(int i=0;i<256;i++)
                    {
                        statics[i]=0;
                    }                for(int i=0;i<256;i++)
                    {
                        if(max < statics[i])
                        {
                            max = statics[i];
                           storeLocation = i;//我敢保证,即使你把外部读storeLocation放在这段代码后面,
    //读取顺序依然是相反的,先读了旧的storelocation,然后它才被更新的。
    //由于对于线程目前不熟练,所以还没办法高效地给你修改代码。
    //我也此贴                    }
                    }
                }
            }).start();
      

  9.   


    (new Thread(){
                public void run()
                {
                    statics = new Integer[256];        
                    for(int i=0;i<256;i++)
                    {
                        statics[i]=0;
                    }                for(int i=0;i<256;i++)
                    {
                        if(max < statics[i])
                        {
                            max = statics[i];
                           storeLocation = i;//我敢保证,即使你把外部读storeLocation放在这段代码后面,
    //读取顺序依然是相反的,先读了旧的storelocation,然后它才被更新的。
    //由于对于线程目前不熟练,所以还没办法高效地给你修改代码。
    //我也此贴                    }
                    }
                }
            }).start();
      

  10.   

    (new Thread(){
                public void run()
                {
                    statics = new Integer[256];        
                    for(int i=0;i<256;i++)
                    {
                        statics[i]=0;
                    }                for(int i=0;i<256;i++)
                    {
                        if(max < statics[i])
                        {
                            max = statics[i];
                           storeLocation = i;
    //我敢保证,即使你把外部读storeLocation放在这段代码后面,
    //读取顺序依然是相反的,先读了旧的storelocation,然后它才被更新的。
    //由于对于线程目前不熟练,所以还没办法高效地给你修改代码。
    //我也此贴                    }
                    }
                }
            }).start();