I have this class:
public class TimeIntCo<T> extends TimeValueCo<Integer>
{
}
I decided that the T type is not needed anymore, and it is not used in the class (I know it is always Integer).
However, I have a lot of references for the class that looks like TimeIntCo<Integer>
.
Is there a way using Eclipse refactoring to remove the T
type without causing any error in references?
I mean to do it in one step and not find&replace.
EDIT: to be more clear - if I just remove T
from class I have about 10,000 errors, I don't want to do it manually, and I prefer not to use find&replace because I consider refactor safer.
Whenever you want to restrict the type parameter to subtypes of a particular class you can use the bounded type parameter. If you just specify a type (class) as bounded parameter, only sub types of that particular class are accepted by the current generic class.
Generic Classes These classes are known as parameterized classes or parameterized types because they accept one or more parameters.
A Generic class simply means that the items or functions in that class can be generalized with the parameter(example T) to specify that we can add any type as a parameter in place of T like Integer, Character, String, Double or any other user-defined type.
Definition: “A generic type is a generic class or interface that is parameterized over types.” Essentially, generic types allow you to write a general, generic class (or method) that works with different types, allowing for code re-use.
Introduce a superclass
public class TimeIntCoSup extends TimeValueCo<Integer> {
}
and change TimeIntCo
to extend it.
public class TimeIntCo<T> extends TimeIntCoSup {
}
Then use Eclipse's Refactor -> Use Supertype Where Possible
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With