I have a couple of functions which requires exact argument type (aka T
):
private void doWork1(T _obj) {...}
private void doWork2
You can use Number
or Object
, which are both common supertypes of Integer
and Double
.
However, the generics are unnecessary:
private void doWork1(T _obj) {...}
is identical to
private void doWork1(Object _obj) {...}
after erasure.
The only point of having a type variable for an input parameter is if:
You need to indicate that the generics of another input parameter need to be related, e.g. you are passing T _obj
and List
.
Note that you don't need a generic type for T _obj1
and T _obj2
, though - that degenerates to the upper bound of T
(e.g. Object
);
If you need it to be related to the return type:
T doWork1(T _obj) { ... }
You don't need either case here, so just remove the unnecessary complication.