Collection are not type safe. We can add any type of data to collection. Because of this , while retrieving the objects from collection , we will get proble at
Conclusion 1 : In java , Parent class or interface reference can hold child class object , this is called polymorphism . But coming to generics polymorphism will be applicable
Before jdk 1.5 ArrayList class is defined as follows. class ArrayList {add(Object o) ;Object get(int index);– –} ➩ See the above code . The argument of add() method is Object,
In this tutorial we are going to learn, how to create custom generic class. See the below example. package sree; public class Student { String name; String id ; public
In this tutorial we are going to learn, What is bounded types and how to use it. See the below example. package sree; import java.util.Date; public class Sample<T> { T
In previous tutorial we used single class or interface as bounded type. But we can apply multiple bounded types at a time. See the below example. public class Sample<T extends
Before jdk 1.5 ArrayList class is defined as follows. class ArrayList {add(Object o) ;Object get(int index);– –} ➩ See the above code . The argument of add() method is Object,
‘?’ is used as wild card character in java generics concept . Before going to learn use of the wild card character, let’s see the sample below. import java.util.ArrayList; import
In previous tutorial, we have seen how to use wild card character . Wild card character allows to pass any type of list as parameter to the method . Then,
If we want to force the method to allow particuler type list or it’s super classes type list as parameter we have to use super keyword. See , below example.