![]() |
Arrays with Generic Type
I'm trying to create a simple database inside Java using seperate chain Hashing. The database stores the many products inside a grocery store. In my createDatabase method, however, it flags (using Eclipse) a warning (not syntax error) when I try to initalize the database, an array of type ArrayList<Product>:
:
public void createDatabase(int maxStorage, double maxLoadFactor) {The warning says: "Type safety: The expression of type ArrayList[] needs unchecked conversion to conform to ArrayList<Product>[]". When I try to fix the suggested problem, a syntax error is flagged: :
ArrayList<Product>[] chainArray = new ArrayList<Product>[databaseSize];Is there a way so that not a single warning or syntax flag is shown? I'm assuming the code would run despite the warning flag, but I'd rather remove it if at all possible. |
I had this problem once and I think it's just a bug in how generics work. For a nasty hack that'll hopefully get it working:
:
private class ProductArray extends ArrayList<Product> {}; // somewhere in your class |
Looks like this works:
:
public void createDatabase(int maxPlayerNumber, double maxLoadFactor) {Thx. Though it's quite unrelated to that warning, a new warning pops up that I usually see when extending many classes. I've never understood what it meant and I believe it starting popping up all over my code once 1.5 came out. It says: "The serializable class ProductArray does not declare a static final serialVersionUID field of type long". Normally, I just ignore it (sometimes I set serialVersionUID to 0, just to shut it up), but what exactly is "serialVersionUID" supposed to be representing? EDIT: And yes, that is a quite different approach than I would have ever thought of. :rolleyes: |
Quote:
|
Quote:
|
if you're referring to the serialVersionID, you're off the mark ;)
|
Quote:
edit: ah, nevermind - i didn't notice you had quoted the Java API earlier, I had just glanced at it, assumed it was a quote from a previous post, and ignored it. d'oh! |
| All times are GMT -5. The time now is 1:25 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC