This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Regarding Warnings in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regarding Warnings in Java" Watch "Regarding Warnings in Java" New topic
Author

Regarding Warnings in Java

Pradeep Balasubramanian
Ranch Hand

Joined: Jun 16, 2008
Posts: 75
while I am compiling a Java program (with or without error), I am getting a warning as follows..

C:\Data\Javic\SCJP 5.O\collections>javac ArraysToListConversion.java
Note: ArraysToListConversion.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.


what does it mean ...


But, I am not getting such warnings while working in Eclipse

Why ???



Regards,<br />Pradeep Balasubramanian<br /> <br />You have to grow from the inside out. None can teach you, none can make you spiritual. There is no other teacher but your own soul. <br /> <br />- Swami Vivekananda
Taariq San
Ranch Hand

Joined: Nov 20, 2007
Posts: 192
Originally posted by Pradeep Balasubramanian:
what does it mean ...


Ah, to know the meaning of life, you should recompile with -Xlint:unchecked.


But, I am not getting such warnings while working in Eclipse

Why ???


You have to turn this feature on somewhere, can't recall where but it's off by default.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38033
    
  22
It most probably means you have not declared your types parameterised (with <Generic> tags). If the Java compilers compile an application without any warnings like that and you have not suppressed any warnings, you can be confident of it not suffering any ClassCastExceptions.

And Eclipse does have such warnings, only they are different; there is a yellow "warning" triangle on the left and hovering your mouse over it you get a warning something like

List is a raw type. References to List<E> should be parameterized.

or similar in the pop-up window.
Taariq San
Ranch Hand

Joined: Nov 20, 2007
Posts: 192
Originally posted by Campbell Ritchie:
And Eclipse does have such warnings, only they are different; there is a yellow "warning" triangle on the left and hovering your mouse over it you get a warning something like

List is a raw type. References to List<E> should be parameterized.

or similar in the pop-up window.


Oi, forgot that, just assumed he meant in the "problems" view.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38033
    
  22
The same warning would appear on the "problems" view on Eclipse too.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

Unless a) the warnings are turned off, or b) the project is setup for Java 1.4


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38033
    
  22
Yes, that would be reasonable if you are using Java 1.4 or older, but turning all the warnings off means "not setting Eclipse up properly" to me.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10170
    
    8

Originally posted by Campbell Ritchie:

And Eclipse does have such warnings, only they are different; there is a yellow "warning" triangle on the left and hovering your mouse over it you get a warning something like


If you dislike using the mouse (like me) you can also select the code which is underlined in yellow/red and hit CTRL+1 to get the same details mentioned by Campbell.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Juan Manuel Alberto de los Santos
Ranch Hand

Joined: Jun 26, 2008
Posts: 48
you have to declare a parameterized type ...



You can disable the Unchecked Warnings, using ...

@Suppress Warnings("unchecked")

via standar anotation.

or compiling using -xlint:unchecked

***

i learned this from

http://www.angelikalanger.com/GenericsFAQ/FAQSections/TechnicalDetails.html#What is an unchecked warning?
[ September 17, 2008: Message edited by: Juan Manuel Alberto de los Santos ]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

Originally posted by Juan Manuel Alberto de los Santos:

Actually, you are warned a line lower, with the add method.

And @SuppressWarnings("unchecked") is without a space
 
Consider Paul's rocket mass heater.
 
subject: Regarding Warnings in Java
 
Similar Threads
calculator program help please
Java 1.5 compile time error
doubt in assert...
Running Bouncy Castle
global properties file