File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding Warnings in Java

 
Pradeep Balasubramanian
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ???

 
Taariq San
Ranch Hand
Posts: 192
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 192
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The same warning would appear on the "problems" view on Eclipse too.
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless a) the warnings are turned off, or b) the project is setup for Java 1.4
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Juan Manuel Alberto de los Santos
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic