Posts

Showing posts from January, 2013

Generics In Java

Generics : Generics add stability to our code by making more of our bugs detectable at compile time. Generics enable types to be parameters when defining classes, interfaces and methods. Benefits of Generics: Strong type check at compile time. Elimination of casts Enabling programmers to implement generic algorithms Generic Types: A generic type is a generic class or interface that is parameterized over types. Generic Class:           Class name<T1,T2,T3.....Tn>           Type parameter section delimited by angle brackets<> follows the class name.            Type parameters are T1,T2,T3....Tn Example:              public class Box<T>                {                    private T t;                 ...