Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot make a static reference to the non-static type MyRunnable
    text
    copied!<p>Here is the whole code :</p> <pre><code>import java.util.ArrayList; public class Test&lt;E extends Comparable&lt;E&gt;&gt;{ ThreadLocal&lt;ArrayList&lt;E&gt;&gt;arraylist=new ThreadLocal&lt;ArrayList&lt;E&gt;&gt;(){ @Override protected ArrayList&lt;E&gt; initialValue() { // TODO Auto-generated method stub //return super.initialValue(); ArrayList&lt;E&gt;arraylist=new ArrayList&lt;E&gt;(); for(int i=0;i&lt;=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&lt;E&gt;myarraylist=(ArrayList&lt;E&gt;) 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&lt;Double&gt;(); System.out.println(test.arraylist.toString()); new Thread(new MyRunnable(test)).start(); new Thread(new MyRunnable(test)).start(); System.out.println(arraylist.toString()); } } </code></pre> <p>my questions are:</p> <ol> <li>Why <code>new Thread(new MyRunnable(test)).start();</code> cause the error:<br> <code>Cannot make a static reference to the non-static type MyRunnable</code>?</li> <li>What does the term "static reference" refer to?</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload