Good day, I decided to go into generics deeper than SomeClass<T> , and jumped at the complexity.

let's say there is a class

 public class SomeClassA<T>{ } 

and class

 public class SomeClassB<X>{ public void someMethod(Object, X){} } 

How do I set generic in SomeClassB so that it has <SomeClassA<T>> at the input and works, respectively, with T

Thank you in advance

  • Do you want to take in someMethod argument of type SomeClassA<T> ? Can you give examples of the alleged code? While not entirely clear. - default locale
  • one
    I do not know how to properly explain. Let's really try the code. someClassB scb = new SomeClassB<SomeClassA<Integer>>; scb.someMethod(new Integer(10)); - Blc_Dragon
  • one
    there is a feeling that I am doing something useless, because the logic of the program will not change in the case of SomeClassA<T> SomeClassB<T> . - Blc_Dragon

1 answer 1

Perhaps you meant inheritance:

 public class MyClass { public static void main(String[] args) { SomeClassB<Integer> scb = new SomeClassB<>(); scb.print(10); } } class SomeClassA<T> { public void print(T obj) { System.out.println(obj.toString()); } } class SomeClassB<T> extends SomeClassA<T> { public void print(T obj) { super.print(obj); } } }