简体   繁体   English

为什么我有错误,但没有异常?

[英]Why I have an error, but not an exception?

documentation 文件

Invoking Object's clone method on an instance that does not implement the Cloneable interface results in the exception CloneNotSupportedException being thrown.在未实现 Cloneable 接口的实例上调用 Object 的 clone 方法会导致抛出异常 CloneNotSupportedException。

Why I have an error为什么我有错误

clone() has protected access in java.lang.Object clone() 在 java.lang.Object 中具有受保护的访问权限

but not CloneNotSupportedException exception?但不是 CloneNotSupportedException 异常?

public class Test
{
    public static void main(String[] args)
    {
        Test2 c1 = new Test2();
        Test2 c2 = (Test2) c1.clone(); // error: clone() has protected access in java.lang.Object
    }
}

class Test2
{

}

Because the error is at compile time.因为错误是在编译时。

Exception are at runtime.异常发生在运行时。 The program didn't even compile, so you didn't reach runtime.该程序甚至没有编译,所以你没有达到运行时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM