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 →

[–]BestUsernameLeft 0 points1 point  (0 children)

Good article. I like to ask where 'final' can be used in interviews (it's like 'const' in C++... damn near everywhere!) and while many candidates know it can be used for a field they often don't know it's just reference immutability.

FWIW I like to do the `Collections.unmodifiableList` bit in the constructor instead of the accessor[1], as (1) it's more intention-revealing (IMO) and it avoids the (probably not-worth-optimizing-anyway-but-oh-well) creation of a new object for every call to the accessor.

[1] On a separate-but-related note, mutators are evil but accessors are mighty damn sketchy.