CodesJava

Easy learning with example program codes

Generics


Generics tutorial in java for beginners and professionals with examples in eclipse on Basics, Generics terms, Generics Examples, wildcard and more.
 
Generics is a way of implementing generic programming. Generic programming provides the facility like for a set of related methods, declare a single method that support any valid types. Generics are introduced in java 5. In java, generics are added because of Compile time type safety.

Let us understand with an example. We have an ArrayList of string type and add an integer type element. Before java 5 this code will compile and throw exception at the runtime which is worse. Generics provides the facility of compile time type safety i.e. compiler check that the correct types should be used at the correct places and no ClassCastException.
 
Working Generics examples programs with output and source code.
 

tutorial:

Generics interview questions in java:

 




Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap