Arrays and Generic Collections

PicoContainer 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);