得到错误为
“ java.io.IOException:无法获取.. \ log \ abc.log的锁”,不确定为什么会发生这种情况。
有人可以帮我吗?谢谢
        logger = LogManager.getLogManager().getLogger(className);
        FileHandler logFile = new FileHandler(file);
        // create txt Formatter
        SimpleFormatter formatterTxt = new SimpleFormatter();
        logFile.setFormatter(formatterTxt);         
        logger.addHandler(logFile);
我想用finalize检查终止条件,但每次都不会执行finalize.谁能告诉我为什么?
public class Test
{
    public static void main(String[] args)
    {   
        Tank tank=new Tank();
        tank.fill();
        System.gc();
    } 
}  
public class Tank    {
    private boolean emptied=true;
    public void fill()
    {
        this.emptied=false;
    }
    public void empty()
    {
        this.emptied=true;
    }
    public Tank()
    {
        this.emptied=true;
    }
    protected void finalize()
    {
        if(this.emptied==false)
        {
            System.out.println("Termination Verification Error: Tank should be emptied");
        }
    }
}
似乎没有意义的子类被强制调用基类的构造函数.如果用户可以创建自己的构造函数而不限于基类,那么它将更加灵活.任何人都可以告诉我为什么在JAVA中强制这种行为?这有什么好处?
class A
{                                                                                                    
  public A(String s)
  { 
    System.out.println(s);
    System.out.println("BASE parameter constructor");
   }   
}
class C extends A
{  
       public C(String s)   
       {
        super(s);// why here compiler force to call constructor of base class
        System.out.println("Sub parameter constructor");
        }
}