小编Cat*_*yan的帖子

java.io.IOException:无法获得锁定

得到错误为

“ 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);
Run Code Online (Sandbox Code Playgroud)

java filehandler

3
推荐指数
2
解决办法
2万
查看次数

为什么没有调用finalize()?

我想用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");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

java finalize

1
推荐指数
1
解决办法
774
查看次数

不明白为什么子类必须显式调用具有参数的基类构造函数

似乎没有意义的子类被强制调用基类的构造函数.如果用户可以创建自己的构造函数而不限于基类,那么它将更加灵活.任何人都可以告诉我为什么在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");
        }
}
Run Code Online (Sandbox Code Playgroud)

java

1
推荐指数
1
解决办法
88
查看次数

标签 统计

java ×3

filehandler ×1

finalize ×1