Skip to content

아이템 13. clone 재정의는 주의해서 진행하라. #42

Answered by corock
YuDeokRin asked this question in 3. 과제
Discussion options

You must be logged in to vote

다시 보니 블로그가 있군요 👍
블로그 내용에서 궁금한 점도 있고, 알게 된 점도 있어 몇 자 적어봅니다.

  1. 초반부에서 protected 에 대한 설명을 작성해주셨습니다.

protected 는 서로 다른 패키지에서 호출할 수 없고, 서로 다른 패키지라도 상속은 가능하다.
그렇기 때문에 clone() 를 사용하려는데 Object 클래스가 필요하지만, protected 때문에 다른 패키지에 있는 Objectclone() 메서드를 호출하지 못한다. ㅠㅠ

이 문장을 여러 번 읽어봤는데 이해가 잘 안되네요. 다른 패키지라면 java.lang 패키지를 말하는 건가요~?

  1. 제가 알기로 Cloneable 인터페이스는 마커용으로 알고 있습니다.

Note that this interface does not contain the clone method. Therefore, it is not possible to clone an object merely by virtue of the fact that it implements this interface. Even if the clone method is invoked reflectively, there is no guarantee that it will succeed.

Javadoc 에 나와 있는 것처럼 Cloneable 인터페이스를 implements 하더라도 복제되는 것을 보장하지 …

Replies: 6 comments 7 replies

Comment options

You must be logged in to vote
2 replies
@YuDeokRin
Comment options

YuDeokRin Jan 1, 2023
Maintainer Author

@chikeem90
Comment options

Comment options

You must be logged in to vote
1 reply
@YuDeokRin
Comment options

YuDeokRin Jan 2, 2023
Maintainer Author

Comment options

You must be logged in to vote
1 reply
@YuDeokRin
Comment options

YuDeokRin Jan 2, 2023
Maintainer Author

Comment options

You must be logged in to vote
2 replies
@chikeem90
Comment options

@YuDeokRin
Comment options

YuDeokRin Jan 2, 2023
Maintainer Author

Answer selected by YuDeokRin
Comment options

You must be logged in to vote
1 reply
@YuDeokRin
Comment options

YuDeokRin Jan 2, 2023
Maintainer Author

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3장 모든 객체의 공통 메서드 이펙티브 자바 3장 (모든 객체의 공통 메서드)
5 participants