User DocumentationOne minute descriptionTwo minute tutorial Five minute introduction Advanced Topics FAQ Container Components Terminology Mock Objects Inversion of Control Types PatternsInversion of ControlDependency Injection Constructor Injection Setter Injection Interface-Impl Separation Lifecycle Antipatterns Developer DocumentationHow To ContributeRelative Volunteering Release Process Project InformationSloganMailing lists Source Repositories Open Issues Blog entries Statistics Team Sister Projects TShirts MiscellaneousDifferentiatorsNirvana Full Sitemap |
Arrays and Generic CollectionsPicoContainer supports injection of arrays. (In a future version it will also support generic collections and maps). Example code: (Just ignore the fact that the classes are static):public static interface Fish { } public static class Cod implements Fish { } public static class Shark implements Fish { } public static class Bowl { private final Fish[] fishes; private final Cod[] cods; public Bowl(Fish[] fishes, Cod[] cods) { this.fishes = fishes; this.cods = cods; } public Fish[] getFishes() { return fishes; } public Cod[] getCods() { return cods; } } Example usage: pico.registerComponentImplementation(Shark.class); pico.registerComponentImplementation(Cod.class); pico.registerComponentImplementation(Bowl.class); bowl = (Bowl) pico.getComponentInstance(Bowl.class); PicoContainer will instantiate the arrays and populate them with all that matches the array type. Behind the scenes something similar to the following is happening: Shark shark = new Shark(); Cod cod = new Cod(); Fish[] fishes = new Fish[]{shark, cod}; Cod[] cods = new Cod[]{cod}; Bowl bowl = new Bowl(fishes, cods); |