public class NumberManager {
private int lastNumber;
//能用上级接口或父类做的事就不要用子类
private List<Integer> queueNumber=new ArrayList<>();
public synchronized Integer generateNewManager(){
queueNumber.add(lastNumber);
return lastNumber++;
}
public synchronized Integer fetchServiceNumber(){
//取走并返回号码队列中第一个号码
return queueNumber.remove(0);
}
}
package com.isoftstone.interview.bank;
import java.util.concurrent.Executors;
public class ServiceWindow {
private CustomerType type=CustomerType.Common;
public void start(){
Executors.newSingleThreadExecutor().execute(new Runnable(){
public void run(){
while(true){
switch(type){
case Common:
Integer number= NumberMachine.getInstance().getCommonManager().fetchServiceNumber();
break;
case Express:
break;
case Vip:
break;
}
}
}
});
}
问题就是写到一半的时候我引用了NumberMachine类的getInstance方法,但是系统报那是个非静态方法,于是我回去看了是有static啊回来一看依然错,然后我用枚举类创建对象也错,我确认了很多次应该是没错的,可它就报错,这啥情况?