Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[아이템 19] 상속을 고려해 설계하고 문서화하라. 그러지 않았다면 상속을 금지하라 #15

Open
punsoo opened this issue May 9, 2021 · 1 comment

Comments

@punsoo
Copy link
Member

punsoo commented May 9, 2021

p. 127에

마지막으로, Serializable을 구현한 상속용 클래스가 readResolve나 writeReplace 메서드를 갖는다면 이 메서드들은 private이 아닌 protected로 선언해야 한다. private으로 선언한다면 하위 클래스에서 무시되기 때문이다.

라고 되어있습니다.
여기서 하위클래스에서 무시된다는 말은 링크와 같이 하위 클래스에서 부모의 private 메서드에 접근이 안된다는 것을 의미하는 것일까요?

@ghojeong
Copy link
Member

ghojeong commented May 9, 2021

하위 클래스에서 부모의 private 메서드에 접근이 안된다는 것

정확히 잘 이해하신 것 같습니다.
참고로 자바의 Serializable 은 굉장히 병맛인게, 하위 클래스에서 private 메서드나 멤버에 접근이 불가능하지만,
막상 Serialize 하면 private 관련된 데이터가 그대로 남아있습니다.
덕분에 일부러 Serialize 해서 private 에 접근하는 병맛스러운 해킹방법이 통합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants