No enclosing instance of type E is accessible. Must qualify the allocation with an enclosin的解决方案
最近用java写一个小程序时编译出现:No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing instance of type E(e.g. x.new A() where x is an instance of E). 原始代码如下:
public class WorkThreadTest {class Worker {private String name; // 名字private long workDuration; // 工作持续时间/*** 构造器*/public Worker(String name, long workDuration) {this.name = name;this.workDuration = workDuration;}/*** 完成工作*/public void doWork() {System.out.println(name + " begins to work...");try {Thread.sleep(workDuration); // 用休眠模拟工作执行的时间} catch (InterruptedException ex) {ex.printStackTrace();}System.out.println(name + " has finished the job...");}}/*** 测试线程**/class WorkerTestThread implements Runnable {private Worker worker;private CountDownLatch cdLatch;public WorkerTestThread(Worker worker, CountDownLatch cdLatch) {this.worker = worker;this.cdLatch = cdLatch;}@Overridepublic void run() {worker.doWork(); // 让工人开始工作cdLatch.countDown(); // 工作完成后倒计时次数减1}}private static final int MAX_WORK_DURATION = 5000; // 最大工作时间private static final int MIN_WORK_DURATION = 1000; // 最
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
