package com.Fooblibar.widgets; public interface Part { ...} public interface Assembly { Collection getParts(); // Returns a collection of Parts } public class Inventory { public static void addAssembly(String name, Collection parts) {...} // Adds an assembly into the DB public static Assembly getAssembly(String name) {...} // Looks up an assembly in the DB }
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<Part> c = new ArrayList<Part>(); c.add(new Guillotine()) ; c.add(new Blade()); Inventory.addAssembly("thingee", c); // pass to "raw type" Collection<Part> k = Inventory.getAssembly("thingee").getParts(); // return from "raw type" } }
Collection
Collection<Part>
Collection<Object>
Collection<?>
$ javac G25.java Note: G25.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. $ java -Xlint:unchecked G25.java G25.java:24: warning: [unchecked] unchecked conversion found : java.util.Collection required: java.util.CollectionCollection k = Inventory.getAssembly("thingee").getParts(); // return from "raw type" ^ 1 warning