problem implementing a generic collection

C

Codex

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.
 
L

Lew

Codex said:
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.
 
T

Tom Hawtin

Codex said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top