Can some one explain to me the private constructor capture idiom with an example and point out where we actually need / do not need this kind of design?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The aim is to capture a temporary value during construction.
An example is given in Solution 53 of Java Puzzlers:
In this case, we want to capture and store the parameter that we wish to pass to the superclass constructor. In order to do so, we create a private helper constructor, which our public constructor then calls.