api java 5 more: should i relapse an array collection?
in idea , i face identical doubt nearing . (yes, i know, ;-) ).
for functions returning collection (which rudimentary ), i always move (in jdk1.4.2) returning an array instead general list, because:
- it enforces returning form (
myobject[]
instead list objects, many some-more type-safe stationary -- 'compilation' -- level) - it suggests 'read-only' impression returned collection (it some-more difficult supplement an component collection, even nonetheless severe 'read-only' keyword c#). same observant 'immutable' given references inside array still modified...
of course, i always create returned array (i arrangement any 'internal' array)
now, jdk5 more, i list<myobject>
i wish to.
what good reasons selecting relapse myobject[]
instead list collection<myobject>
coding java5 ?
bonus, collection<myobject>
used, illusory to:
- enforce read-only charge returned collection ? (no
add()
remove()
possible) - enforce an permanent aspect returned collection ? (even references collection modified)
ps: definitely have one.
Comments
Post a Comment