Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I remove generic type from class using refactoring

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.

like image 795
oshai Avatar asked Jun 22 '11 13:06

oshai


People also ask

How can we restrict generic to a subclass of particular class?

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.

What is the generic class type called?

Generic Classes These classes are known as parameterized classes or parameterized types because they accept one or more parameters.

How do you define a class which accepts a generic type parameter?

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.

What does generic type mean in Java?

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.


1 Answers

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

like image 132
artbristol Avatar answered Oct 10 '22 08:10

artbristol