C# allows for getting the type of generic parameters using the typeof(T)
method without the need to instantiating the T
parameter. But in Java anytime I have generic T
parameter and I want to determine the type I have to create an instance of that parameter,for example by using the Class<T> Type
, to figure out what type that is.
In comparison with what C# provides, this approach in Java looks unnecessarily lengthy and complicated.
I would like to know what is best alternative to determine the type of a generic parameter without the need to instantiate that (for example if (T is Integer)
).