Object类中的clone()实现 [英] clone () implementation in Object class

查看:75
本文介绍了Object类中的clone()实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读这篇文章,内容为

I was reading this article and it says that


对象 clone 方法非常棘手。它是基于字段副本,并且是额外语言。它创建一个对象而不调用构造函数。

Object's clone method is very tricky. It's based on field copies, and it's "extra-linguistic." It creates an object without calling a constructor".

我在 grep代码是以下行:

protected native Object clone() throws CloneNotSupportedException;

我在这里缺少什么?

推荐答案

您错过了 native 表示它是用非Java代码实现的(在这种情况下,它是在JVM本身中实现的。)

You're missing the native which means it's implemented in non-Java code (in this case it's implemented in the JVM itself).

clone 的功能无法在Java代码中实现(这使其成为问题)。

That's because the exact functionality of clone can not be implemented in Java code (which makes it so problematic).

这篇关于Object类中的clone()实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆