Generics

What is Generics:


Generic are introduced to programming language from v5, also it maintains support to Raw type.
Generic type is a class or interface followed by Parameter. the parameter is given in angular Bracket.
Generiic allow us to pass the type(Integer ,String ..user defined type) to method ,class or interface.

Parameter can be Formal or actual .
Formal Paramter is used when we declare the Generic type the actual parameter is used when we pass the values.

Why ?


It is better to detect the bug at earlist . the GENERICS provides the type safety so compiler complains when you to enter values other than one specified in generic parameter.
thus ensuring destructibility at compile time (rather than leaving it for run time error .)

Following rules are described –
  1. Item 26: Don’t use raw types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
  2. Item 27: Eliminate unchecked warnings. . . . . . . . . . . . . . . . . . . . 123
  3. Item 28: Prefer lists to arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
  4. Item 29: Favor generic types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
  5. Item 30: Favor generic methods . . . . . . . . . . . . . . . . . . . . . . . . . . 135
  6. Item 31: Use bounded wildcards to increase API flexibility . . . . 139
  7. Item 32: Combine generics and varargs judiciously. . . . . . . . . . . 146
  8. Item 33: Consider typesafe heterogeneous containers . . . . . . . . . 151

MemoryMap