1. Conceptual generics are parameterized types. The advantage of generics is to check the type security during compilation, and all the forced conversions are both automatic and implicit, improving the code reuse rate. 2. case 1) first look at the following case: // not applicable to generic programming Apple app0 = new Apple (); Apple app1 = new Apple (); List li = new ArrayList (); li. add (app0); // No error can be found when you add a non-required type. Li. add (app1); Apple appUsed = (Apple) li. get (0); // use generic programming as follows: Apple app0 = new Apple (); Apple app1 = new Apple (); list <Apple> li = new ArrayList <Apple> (); li. add (app0); // if the type of the added object is incorrect, the compiler will find it. Specify the object type to be held by the container, and use the compiler to ensure the correctness of the type. Li. add (app1); Apple appUsed = li. get (0); advantages of using generics: large applications can significantly reduce the complexity of the program; generics can bring about large optimizations: such errors can be found during compilation, in addition, you do not need to judge the type when extracting elements, thus improving the program running timeliness rate. 2) A generic class has two classes: the following: Construct the objects of the two classes and print their respective member x. Public class StringFoo {private String x; public StringFoo (String x) {this. x = x;} public String getX () {return x;} public void setX (String x) {this. x = x ;}} public class DoubleFoo {private Double x; public DoubleFoo (Double x) {this. x = x;} public Double getX () {return x;} public void setX (Double x) {this. x = x ;}} use generics to implement public class GenericsFoo <T> {private T x; public GenericsFoo (T X) {this. x = x;} public T getX () {return x;} public void setX (T x) {this. x = x ;}} code implementation: public class GenericsFooDemo {public static void main (String args []) {GenericsFoo <String> strFoo = new GenericsFoo <String> ("Hello Generics! "); GenericsFoo <Double> douFoo = new GenericsFoo <Double> (new Double (" 33 ")); genericsFoo <Object> objFoo = new GenericsFoo <Object> (new Object (); System. out. println ("strFoo. getX = "+ strFoo. getX (); System. out. println ("douFoo. getX = "+ douFoo. getX (); System. out. println ("objFoo. getX = "+ objFoo. getX () ;}} 3) whether the generic method has a generic method, and whether the class is generic. To define a generic method, you only need to place the list of generic parameters before the return value. Public class ExampleA {public <T> void f (T x) {System. out. println (x. getClass (). getName ();} public static void main (String [] args) {ExampleA ea = new ExampleA (); ea. f ("ea"); ea. f (10); ea. f ('A') ;}} when using the generic method, you do not need to specify the parameter type. The compiler will find the specific type by itself. In addition to different definitions, generic methods call similar methods. Note that a static method cannot access the type parameters of a generic class. Therefore, to use a static method, you must make it a generic method. Www.2cto.com 4) restrict generic and wildcard class GenericsFoo <T extends Collection>. In this way, the generic T in the class can only be the implementation class of the Collection interface, and an error occurs when the non-Collection interface is imported. Class GenericsFoo <? Extends Collection>, "?" Represents the unknown type (wildcard), which is the Collection interface. <? Extends type> indicates that this type is a child type of a certain type.