@@ -5658,6 +5658,123 @@ A2<ArrayList<Object>> a1 = new A2< ArrayList<Object>>() {
56585658
56595659</h3 >
56605660
5661+ <h3 ><i >Other Examples: </i ></h3 >
5662+ <ul >
5663+ <h3 ><li ><a href =" https://github.com/AvinandanBose/JavaGeneric/blob/main/Example6.java " > 1. Multiple Upper Bound Wild Card </li ></h3 >
5664+
5665+ ``` Syntax
5666+
5667+ interface A<T> {
5668+ public T get(T a);
5669+ }
5670+
5671+ interface B<T> {
5672+ public T get(T b);
5673+ }
5674+
5675+ class C<T> implements A<T>, B<T> {
5676+ public T get(T c) {
5677+ return c;
5678+ }
5679+ }
5680+
5681+ class Example<T extends A<? extends Number> & B<? extends Number>>{
5682+ public static void main(String[] args) {
5683+ A<Number> a = new A<Number>(){
5684+ @Override
5685+ public Number get(Number a) {
5686+ return a;
5687+ }
5688+ };
5689+
5690+ System.out.println(a.get(1));
5691+
5692+ B<Integer> b = new B<Integer>(){
5693+ @Override
5694+ public Integer get(Integer b) {
5695+ return b;
5696+ }
5697+ };
5698+
5699+ System.out.println(b.get(2));
5700+
5701+
5702+ }
5703+
5704+ // Same for Double, Float,
5705+ // Long, Short, Byte,
5706+ // Which are extended by Number
5707+
5708+
5709+
5710+
5711+ }
5712+
5713+ ```
5714+
5715+ <h3 ><li ><a href =" https://github.com/AvinandanBose/JavaGeneric/blob/main/Example7.java " > 2. Multiple Upper Bound Wild Card with Lower Bound</li ></h3 >
5716+
5717+ ``` Syntax
5718+
5719+ import java.io.Serializable;
5720+
5721+ interface A1<T> {
5722+ public T get(T a);
5723+ }
5724+
5725+ interface B1<T> {
5726+ public T get(T b);
5727+ }
5728+
5729+ class C1<T> implements A1<T>, B1<T> {
5730+ public T get(T c) {
5731+ return c;
5732+ }
5733+ }
5734+
5735+
5736+ public class Example<T extends A1<? super Number> & B1<? super Number>> {
5737+
5738+ public static void main(String[] args) {
5739+ A1<Number> a = new A1<Number>(){
5740+ @Override
5741+ public Number get(Number a) {
5742+ return a;
5743+ }
5744+ };
5745+
5746+ System.out.println(a.get(1));
5747+
5748+ B1<Object> b = new B1<Object>(){
5749+ @Override
5750+ public Object get(Object b) {
5751+ return b;
5752+ }
5753+ };
5754+
5755+ System.out.println(b.get(2));
5756+
5757+
5758+ B1<Serializable> b2 = new B1<Serializable>() {
5759+ @Override
5760+ public Serializable get(Serializable b) {
5761+ return b;
5762+ }
5763+ };
5764+
5765+ System.out.println(b2.get(3));
5766+
5767+ }
5768+
5769+
5770+
5771+ }
5772+
5773+
5774+ ```
5775+
5776+ </ul >
5777+
56615778<h3 ><i > Hence, everything depends upon what Type the Super Interface / Class have .</i ></h3 >
56625779
56635780<h3 align =" Left " >
@@ -5689,6 +5806,8 @@ Eg <type> e = Eg<type>{
56895806
56905807</ul >
56915808
5809+ <h2 ><li >4. Generic Inner Class </li ></h2 >
5810+
56925811</ul >
56935812
56945813<h1 align =" Center " > ------x-------</h1 >
0 commit comments