my dog learned polymorphism
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Array problem" Watch "Array problem" New topic

Array problem

Suja Mudunuri

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();
brands.add("Jack Amber");

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

when I compile with -Xlint, i get the following errors 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

Joined: Jul 08, 2003
Posts: 24193

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

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

Joined: Jul 28, 2004
Posts: 14
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.

I agree. Here's the link:
subject: Array problem
It's not a secret anymore!