Is it possible to write an implementation of List<T> that only works
with a single type? I have an method that returns List<MyCoolClass>
and want to write an implementation of a List of MyCoolClass that runs
particularly fast - but because of that, I can't make the
implementation fully generic.
Lew - 21 Apr 2007 14:59 GMT
> Is it possible to write an implementation of List<T> that only works
> with a single type? I have an method that returns List<MyCoolClass>
> and want to write an implementation of a List of MyCoolClass that runs
> particularly fast - but because of that, I can't make the
> implementation fully generic.
Genericity has no impact on runtime speed.
Two important questions for you:
Are you sure you need a custom List?
What would your implementation offer that the standard implementations don't?
That said, you always write a
public class CoolList implements List<MyCoolClass>
or
public class CoolList extends AbstractList<MyCoolClass>
if you really wanted.
BTW, having the word part "Class" in a class name is silly. The idea of the
name is to hint at the class's purpose, semantics or function. Of course it's
a class; putting the "Class" decorator in there adds nothing.

Signature
Lew
Tom Hawtin - 21 Apr 2007 15:02 GMT
> Is it possible to write an implementation of List<T> that only works
> with a single type? I have an method that returns List<MyCoolClass>
> and want to write an implementation of a List of MyCoolClass that runs
> particularly fast - but because of that, I can't make the
> implementation fully generic.
class MyCoolList implements List<MyCoolClass> {
...
}
Or more generally:
class MyCoolList<T extends MyCoolClass> implements List<T> {
...
}
Are you sure it's going to make a significance performance difference?
Tom Hawtin