Skip to main content

Posts

Showing posts from July, 2020

Java generics ? super Type and ? extends Type

Hy All, in this post, going to tell you real-time scenario when you use super and extends ? super C This indicates the lower bound, what exactly means that it can hold a list of object which is super to type C or C ? extends A This indicates the upper bound, what exactly means that it can hold a list of object which is a child to type A or A. Below is provided an example for the same, package com.vinay.stock.poc; import java.util.ArrayList; import java.util.List; /** * @author 912vi */ public class GenericDemo { public static void main(String[] args) { List<A> list = new ArrayList<>(); list.add( new A()); list.add( new B()); list.add( new C()); test2 (list); List<B> list1 = new ArrayList<>(); list1.add( new B()); list1.add( new C()); test2 (list1); /* List<AA> list2 = new ArrayList<>(); test2(list2);// compile time error because upper boun...