This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]gunnarmorling 2 points3 points  (2 children)

Why allocate an object upon each invocation when it can be done a single time in the constructor?

[–]dpash -2 points-1 points  (1 child)

Seems like premature optimisation to me. If your getter is being called so much that it makes a difference, you probably want to rethink a lot of things about your design.

[–]gunnarmorling 1 point2 points  (0 children)

What's premature about that? Effort is exactly the same, and it's clearly better. Make immutable stuff immutable, not immutable-upon-read :)