No enclosing instance of type is accessible. [duplicate]

我只是一个虾纸丫 提交于 2019-12-03 03:29:00

If you change class MyThread to be static, you eliminate the problem:

public static final class MyThread implements Runnable

Since your main() method is static, you can't rely on non-static types or fields of the enclosing class without first creating an instance of the enclosing class. Better, though, is to not even need such access, which is accomplished by making the class in question static.

Since MyThread is an inner class you have to access it using an instance of MyThreadTest:

public static void main(String args[]) {
    MyThreadTest test = new MyThreadTest();
    new Thread(test.new MyThread(new Integer(1),test)).start();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!