Thursday, 8 June 2017

Java Tutorial: Generics in java | Java Generics [Lower bounded wildcard in Java Generics] ~ foundjava


Click here to watch in Youtube :
https://www.youtube.com/watch?v=M7LaKqw7tfw&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial: Generics in java | Java Generics [Lower bounded wildcard in Java Generics] 
Java Tutorial: Generics in java | Java Generics [Lower bounded wildcard in Java Generics] 
GenericDemo.java
import java.util.ArrayList;
import java.util.List;

public class GenericDemo
{

    public static void main(String[] args)
    {
        
        List<Integer> integerList = new ArrayList<Integer>();
        addIntegers(integerList);

        List<Number> numberList = new ArrayList<Number>();
        addIntegers(numberList);

    }

    public static void addIntegers(List<? super Integer> list)
    {
        list.add(new Integer(50));
        System.out.println(list);
    }

}
Output
[50]
[50]
Click the below link to download the code:

CLICK HERE

No comments:

Post a Comment