The Artima Developer Community
Sponsored Link

Java Answers Forum
Warning: Unchecked call

6 replies on 1 page. Most recent reply: Nov 19, 2009 10:21 AM by Bryan Davis

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
cBin

Posts: 13
Nickname: cbb
Registered: Mar, 2005

Warning: Unchecked call Posted: Sep 12, 2005 12:41 AM
Reply to this message Reply
Advertisement
I am trying to use an arrayList and when I compile I get this warning about my add() and get() methods. Do I need to add bounds checking or something?

I am using NetBeans and it also suggested when I was compiling singly (not the whole main project) that I input "-Xlint:unchecked" in the compiling options.

Anyone know what is going on, and how I can fix it?


Clayton


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Warning: Unchecked call Posted: Sep 12, 2005 1:21 AM
Reply to this message Reply
You are using Java 5 it enforces type-checking,
Google Java Generics (if you are not yet familiar
with the new aspects introduced to the language).

cBin

Posts: 13
Nickname: cbb
Registered: Mar, 2005

Re: Warning: Unchecked call Posted: Sep 12, 2005 3:28 AM
Reply to this message Reply
Does this mean that I have to write things like
ArrayList L= new ArrayList();
(double)L.add(56.3);


clayton

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Warning: Unchecked call Posted: Sep 12, 2005 5:12 AM
Reply to this message Reply
> Does this mean that I have to write things like
>
ArrayList L= new ArrayList();
> (double)L.add(56.3);

>
> clayton

No it means you have to write things like:

ArrayList <Double> L = new ArrayList<Double>();
L.add(new Double(56.3));

Quite a drag hey? In the long run if you polish up
your code it sometimes prooves to be useful, however
it is quite a drag in the beginning.

Google Java Generics, you will find it extremely
odd and interesting at the same time.

Spike

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Warning: Unchecked call Posted: Sep 12, 2005 5:18 AM
Reply to this message Reply
> Does this mean that I have to write things like
>
ArrayList L= new ArrayList();
> (double)L.add(56.3);

>
> clayton

Not quite sure but I think your approach would work too.
However note that it would be

L.add((double)56.3);

and not:

> (double)L.add(56.3);

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Warning: Unchecked call Posted: Sep 12, 2005 7:39 AM
Reply to this message Reply
Declare your ArrayList this way:

ArrayList<Double> myList = new ArrayList<Double>();

This will have 2 effects.

1. The list accepts only Double elements and nothing else
(Of course thanks to Auto-Wrap you can also add double-values)

2. the get(), firstElement() ... Methods don't return a Object, but they deliver a Double element.
Double d = myList.get(0);
this will actually compile
You won't have to cast the returned element anymore.

The "unchekced operations" or however Java calls them are no problem if you declare the arraylists and vectors like shown on top.

Bryan Davis

Posts: 1
Nickname: fire00f1y
Registered: Nov, 2009

Re: Warning: Unchecked call Posted: Nov 19, 2009 10:21 AM
Reply to this message Reply
> Google Java Generics, you will find it extremely
> odd and interesting at the same time.
>
> Spike

Generics were one of the main things that threw me off when learning, but they are extremely helpful in various situations. When you google it, return to the forums with the hundreds of questions you will inevitably have - everyone had trouble with them to begin with (unless you're super awesome, i guess :-\)

Flat View: This topic has 6 replies on 1 page
Topic: illegal start of expression... Previous Topic   Next Topic Topic: write a simple java code

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use