Thursday, 12 March 2015

GENERIC (Core JAVA)

·         It is used to store similar type of data
·         Whenever all elements of collection type are same then we go for generic
·         If a collection is declared with generic then we cannot store element apart from generic type
·         If collection is defined with generic then no need to downcast explicitly each element. Java does automatic down casting (implicitly) for that
ArrayList<string> l1 = new ArrayList<string>();
In this only string object can be stored.
Where l1 is an array list of string type then we can store only string object inside this array list

NOTE : Generic should be used when ever similar types of objects are stored in collection

No comments:

Post a Comment