Object[] 如何可克隆

发布于 2024-08-29 05:51:38 字数 131 浏览 3 评论 0原文

Object[] o = new Object[]{};
System.out.println(o instanceof Cloneable);

这给出了 true 作为 o/p。我不明白为什么?

Object[] o = new Object[]{};
System.out.println(o instanceof Cloneable);

This gives true as o/p. I could not understand why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扛刀软妹 2024-09-05 05:51:38

Java 中的所有数组都是可克隆和可序列化的。

数组上的克隆仅复制数组(浅复制,而不克隆内容)。

All arrays in Java are Cloneable and Serializable.

A clone on an array just copies the array (shallow copy, not cloning the contents).

情栀口红 2024-09-05 05:51:38

基本上,数组支持(浅)克隆。

来自 JLS 的第 10.7 节

数组类型的成员都是
以下内容:

  • 公共最终字段长度,其中包含组件的数量
    数组(长度可以是正数或
    零)。
  • 公共方法克隆,覆盖同名方法
    在类 Object 中并且抛出没有检查
    例外情况。的返回类型
    数组类型 T[] 的克隆方法是
    T[]。
  • 继承自Object类的所有成员;对象的唯一方法
    不继承的是它的clone方法。

每个数组都实现接口
可克隆和 java.io.Serialized。

Arrays support (shallow) cloning, basically.

From section 10.7 of the JLS:

The members of an array type are all
of the following:

  • The public final field length, which contains the number of components of
    the array (length may be positive or
    zero).
  • The public method clone, which overrides the method of the same name
    in class Object and throws no checked
    exceptions. The return type of the
    clone method of an array type T[] is
    T[].
  • All the members inherited from class Object; the only method of Object that
    is not inherited is its clone method.

and

Every array implements the interfaces
Cloneable and java.io.Serializable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文