How does Object class implement clone() method

前端 未结 2 600
刺人心
刺人心 2020-12-31 17:56

In a book on Core Java, I found this excerpt :

Think about the way in which the Object class can implement clone. It knows nothing about the objec

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-31 18:42

    Actually, clone() is implemented in native code, so I assume it just does a memory copy (copy all the bytes) without knowing the contents.

    Besides that, there is the Reflection API to gain knowlegde about a class (which would be slower, however).

提交回复
热议问题