Some months ago, I thought it would be nice to be able to directly bind a Collection with Guice-created elements. That turned out to be a bad idea for my project, but I've had the first hour or two of a proof of concept sitting in Eclipse ever since.
I took another step on that proof of concept today, and more or less successfully got a CollectionBindingBuilder to work:
b.bindSetOf(StringHolder.class).toElements(StringHolder1.class, StringHolder2.class);
StringHolder1 and StringHolder2 are implementations of StringHolder, and are created and injected by Guice as normal. A Set<StringHolder> is constructed and populated with the Guice-created StringHolder1 and StringHolder2 instances, and then injected into a client class.
This is all pretty rough and untested at the moment, and would require a lot of work to complete. I say it "more or less" works because there's a warning about a generic array creation for the varargs in the binding line above.
So, now that I know it can be done but before I turn a fun trick into a major project, what does everyone think of the idea? Is this kind of collection injection a feature anyone would particularly like to see, or particularly prefer *not* to see?
--Logan