A nice thing about parameterized classes in Java is that you can extract and access information about class type arguments at runtime (for an explanation about parameters and arguments see Parameters and arguments). Let’s say that we have an abstract parameterized superclass that has a method which provides some common functionality to all its subclasses. And inside that method we wanted to know what is the class type argument specified by the subclass.

public abstract class GenericAbstractSuperclass<T> { public void foo() { // here we wanted to know what is the class type argument } } public class GenericClass1 extends GenericAbstractSuperclass<Integer> { // subclass methods } public class GenericClass2 extends GenericAbstractSuperclass<String> { // subclass methods }

In above example, method foo() has to access class type argument. In case of GenericClass1 it has to get Integer and in case of GenericClass2 it has to get String. Below is listed a utility class that can accomplish this.

Read More »

di di

azagorneanu?d%3DyIl2AUoC8zA azagorneanu?i%3DlEWaFZwNeJY:GTYUI0bniG8:-BTjWOF_DHI azagorneanu?d%3Dqj6IDK7rITs azagorneanu?i%3DlEWaFZwNeJY:GTYUI0bniG8:4cEx4HpKnUU lEWaFZwNeJY