package com.Fooblibar.widgets; public interface Part { ... } public interface Assembly { Collection<Part> getParts(); // Returns a collection of Parts } public class Inventory { public static void addAssembly(String name, Collection<Part> parts) {...} public static Assembly getAssembly(String name) {...} }
package com.mycompany.inventory; import com.Fooblibar.widgets.*; public class Blade implements Part { ... } public class Guillotine implements Part { ... } public class Main { public static void main(String[] args) { Collection c = new ArrayList(); c.add(new Guillotine()) ; c.add(new Blade()); Inventory.addAssembly("thingee", c); // 1: unchecked warning} Collection k = Inventory.getAssembly("thingee").getParts(); } }