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