Results 1 to 2 of 2
Thread: Basics on collections
- 12-11-2011, 07:47 AM #1
Member
- Join Date
- Dec 2011
- Posts
- 34
- Rep Power
- 0
Basics on collections
Hi guys,
I'm trying to think of the most intelligent way to do the following: I want to write a class that contains a collection Cache of objects of type Member. The Member class is nested within the Cache class. Different classes should be able to call the Cache, but I want to maintain a single static set of the elements going into the Cache. A few questions arise in this case:
1. How do I declare the set to be used within the Cache? (Right now, when declaring global field for my class, I have
private static LinkedList<CacheMember> mru_list = null; as a global field for the Cache class, but does this mean that every time the Cache class is called, my static list is getting reset to null? How can I avoid this? (I tried simply writing
private static LinkedList<CacheMember> mru_list; at the declaration of my global field, but the problem is that I heard it was bad practice to leave a field uninitialized, so I wanted to avoid doing this...))
2. Is the Cache class begging to implement the Collection interface? (This isn’t a school project, I’m simply trying to become a better programmer, so I’d like to follow good logical form.)
Any feedback would be greatly appreciated!
- 12-11-2011, 08:54 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 28
Re: Basics on collections
A static member is only initialized once (when the class has just been loaded), so you can do this:
Java Code:public class Cache { private static LinkedList<Member> mruList= new LinkedList<MemberL>(); ... }
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
Similar Threads
-
Collections
By NatureFreshMilk in forum New To JavaReplies: 12Last Post: 05-23-2011, 09:12 AM -
Collections help.
By YoungJavaBoy in forum New To JavaReplies: 3Last Post: 03-15-2011, 12:14 AM -
Help collections
By nikosv in forum New To JavaReplies: 8Last Post: 12-13-2010, 06:29 PM -
Collections
By Cbani in forum New To JavaReplies: 3Last Post: 02-16-2010, 03:46 PM -
Collections Help
By Dr Gonzo in forum New To JavaReplies: 0Last Post: 12-07-2008, 10:15 PM
Bookmarks