Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

problem implementing a generic collection

Thread view: 
Codex - 21 Apr 2007 14:53 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.
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.