Ne peut pas faire une référence statique pour les non-statique de type MyRunnable

Voici le code entier :

import java.util.ArrayList;
public class Test<E extends Comparable<E>>{
ThreadLocal<ArrayList<E>>arraylist=new ThreadLocal<ArrayList<E>>(){
@Override
protected ArrayList<E> initialValue() {
//TODO Auto-generated method stub
//return super.initialValue();
ArrayList<E>arraylist=new ArrayList<E>();
for(int i=0;i<=20;i++)
arraylist.add((E) new Integer(i));
return arraylist;
}
};
class MyRunnable implements Runnable{
private Test mytest;
public MyRunnable(Test test){
mytest=test;
//TODO Auto-generated constructor stub
}
@Override
public void run() {
System.out.println("before"+mytest.arraylist.toString());
ArrayList<E>myarraylist=(ArrayList<E>) mytest.arraylist.get();
myarraylist.add((E) new Double(Math.random()));
mytest.arraylist.set(myarraylist);
System.out.println("after"+mytest.arraylist.toString());
}
//TODO Auto-generated method stub
}
public static void main(String[] args){
Test test=new Test<Double>();
System.out.println(test.arraylist.toString());
new Thread(new MyRunnable(test)).start();
new Thread(new MyRunnable(test)).start();
System.out.println(arraylist.toString());
}
}

mes questions sont:

  1. Pourquoi new Thread(new MyRunnable(test)).start(); la cause de l'erreur:

    Cannot make a static reference to the non-static type MyRunnable?
  2. Que signifie le terme "point de référence fixe"?

OriginalL'auteur kaiwii ho | 2012-09-17