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

[아이템 90] 직렬화된 인스턴스 대신 직렬화 프록시 사용을 검토하라 #16

Open
punsoo opened this issue May 27, 2021 · 2 comments

Comments

@punsoo
Copy link
Member

punsoo commented May 27, 2021

마지막 페이지(p. 482)를 보면

두 번째, 객체 그래프에 순환이 있는 클래스에도 적용할 수 없다. 이런 객체의 메서드를 직렬화 프록시의 readResolve 안에서 호출하려 하면 ClassCastException이 발생할 것이다. 직렬화 프록시만 가졌을 뿐 실제 객체는 아직 만들어진 것이 아니기 때문이다.

객체 그래프 순환 (순환 참조를 말하는 거 같습니다?)이랑 readResolve 메소드를 사용함에 있어 실제 객체의 생성이랑 무슨 관련이 있는 것인가요?

@ghojeong
Copy link
Member

질문 주신 quote 의 실제 영어 원본은 다음과 같습니다.

Also, it is not compatible with some classes whose object graphs contain circularities: if you attempt to invoke a method on such an object from within its serialization proxy’s readResolve method, you’ll get a ClassCastException because you don’t have the object yet, only its serialization proxy.

@ghojeong
Copy link
Member

invoke a method on such an object from within its serialization proxy’s readResolve method

이 부분의 한국어 번역이 매우 요상하게 되어 있네요.
결국 말하고자 하는 바는 아직 메모리 위에 인스턴스화 하지 않은 객체의 메서드를 호출할 수 없다는 뜻입니다.

readResolve 메소드의 호출의 문제가 아니라, readResolve 안에서 직렬화한 객체의 메소드 호출이 문제가 된다는 뜻입니다.
아직 해당 객체가 실제 인스턴스로 생성되있지 않을 수도 있으니까요,

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