The example on avoiding arrays is incorrect because Enum.values() performs a defensive copy.
LouisCAD opened this issue · comments
api-guidelines/docs/topics/jvm-api-guidelines-predictability.md
Lines 152 to 170 in 461bd2b
This topic can be rephrased better, indeed.
The underlying point is to avoid arrays, because otherwise authors are forced to make a defensive copy (and that's not that great -- it's hard to reason about in the long run; this is exactly the reason Enum.values()
is deprecated for good). We should shift focus to that point rather than "do a defensive copy otherwise"
Of course, we meant to say, "If enum would return not a defensive copy, then… And defensive copies might be expensive."