android - Builders - creates a new instance each time? -
i'm using couple of builders make bunch of objects. i'm doing this:
list<productofbuilder> list; builder b = new builder(); for(some iterable in i) { b.setsomeparam(i); list.add(b.build()); }
is okay do? in other words, builder create new instance of productofbuilder
each build()
?
is okay do? in other words, builder create new instance of productofbuilder each
no not. accordingly code posted changing same reference. in end list contains n builder, content of last call setsomeparam
.
it different if have collection
of objects builder supposed build, , calling @ every iteration build()
.
list<typetobuild> list; typetobuild.bilder builder; (type t : parmas) { builder.setparamns(t); list.add(builder.build()); }
Comments
Post a Comment