Wednesday, 17 May 2017

Java Tutorial: Generics in java | Java Generics [The super wildcard boundary]


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

Click the below Image to Enlarge
Java Tutorial: Generics in java | Java Generics [The super wildcard boundary] 
A.java
public class A
{
    private int value = 10;

    public int getValue()
    {
        return value;
    }

    public void setValue(int value)
    {
        this.value = value;
    }

}
B.java
public class B extends A
{

}
C.java
public class C extends A
{

}
GenericDemo.java
import java.util.ArrayList;
import java.util.List;

public class GenericDemo
{

    public static void main(String[] args)
    {
        GenericDemo genericDemo = new GenericDemo();
        
        List<A>      listA      = new ArrayList<A>();
        genericDemo.insertElements(listA);      
        System.out.println("listA = "+listA);

        List<Object> listObject = new ArrayList<Object>();
        genericDemo.insertElements(listObject);     
        System.out.println("listObject =  "+listObject);
    }

    public void insertElements(List<? super A> list)
    {
        list.add(new A());
        list.add(new B());
        list.add(new C());
    }

}
Output
listA = [A@15db9742, B@6d06d69c, C@7852e922]
listObject =  [A@4e25154f, B@70dea4e, C@5c647e05]
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/GenericsDemo_super_wildcard_boundary_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/GenericsDemo_super_wildcard_boundary_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/539015917c8406e4be671410d713073b3971d1a5/BasicJava/GenericsDemo_super_wildcard_boundary_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge