aspose file tools*
The moose likes Java in General and the fly likes Array problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Array problem" Watch "Array problem" New topic
Author

Array problem

Suja Mudunuri
Greenhorn

Joined: Jul 28, 2004
Posts: 14
I keep getting error with Array List. I am not able to understand what the problem is. Below is my code Can somebody please help me?

package com.example.model;
import java.util.*;
public class BeerExpert{
public List getBrands(String color){
List brands = new ArrayList();
if(color.equals("amber")){
brands.add("Jack Amber");
}
return(brands);
}
}

I am getting the following errors
Note: BeerExpert.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

when I compile with -Xlint, i get the following errors
BeerExpert.java:8: warning: [unchecked] unchecked call to add(E) as a member of
the raw type java.util.List
brands.add("Jack Amber");
^
1 warning


Sujatha Mudunuri<br />SCJP 1.4<br />(Preparing SCWCD 1.4)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

This is not an error -- it's a warning, and can be safely ignored.

Basically, what's going on is that "Tiger" -- Java 1.5 -- changes some of the rules. You're using a book (like 99% of Java books!) that was written before Tiger, and so it doesn't takes these new rules into account.

If the warnings really bother you, you can do one of two things:

1) Compile like this, with the "-source 1.4" flag:

javac -source 1.4 BeerExpert.java


2) Use JDK 1.4.2, still available from Sun, instead of 1.5. Many (if not most) companies are still using it as well.


[Jess in Action][AskingGoodQuestions]
K Riaz
Ranch Hand

Joined: Jan 08, 2005
Posts: 375
Works fine for me [java version "1.4.2_03"].
Suja Mudunuri
Greenhorn

Joined: Jul 28, 2004
Posts: 14
Ernest,
Thank You very much for the clarification. I was not able to figureout what the problem was. compiled without warning with 1.4. Thanks again for a quick response.

Sujatha.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array problem