Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unchecked or unsafe operations

 
Niyas Ahmed Sheikh
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

While I am trying to compile the java prgoram, I am getting the following error:



What is that error? How to resolve it? Pls Help.
 
Steffen Reinhard
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've seen a couple of these, too ... Basically, this isn't exactly an error message, it's just a javac version 1.5.something compiler warning. Recompiling with "-Xlint:unchecked" won't make things much clearer. I did. It didn't.

As you are not dealing with a compile-time error, the warning won't keep your code from running (as long as you don't have any
real errors in your code). If the chatty compiler messages keep bothering you, consider switching back to good old SDK 1.4 (if you don't need any of the additional features of Java 1.5). To do this you will have to reconfigure your IDE. If you don't use an IDE you will have to set a couple of environment variables (taking for granted you still have some SDK 1.4.something stuffed away on your system, otherwise just download and install according to instructions given for your os).

I hope this will help.

Cheers -

Steffen
[ August 03, 2005: Message edited by: Steffen Reinhard ]
 
Niyas Ahmed Sheikh
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So... what is the next step for this?
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So... what is the next step for this?


Generics in the Java� Programming Language
Java Generics FAQs, by Angelika Langer
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you should definitely read those links and try to learn some more about Generics. Although Steffen is right that the messages are only warnings rather than errors, generics are quite a useful tool to provide additional compile-time type safety.
 
Philip Heller
author
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generics are a new thing in release 5.0, and if you don't use them then sometimes the compiles wags a finger at you. (No, not that finger!)

To understand generics ... well, to scrath the surface ... think of the Vector class. You used to use vectors like this:



Usually vectors (and other collections) are homogeneous. That is, even though they can contain data of all different types, they most often don't. A common bug is adding the wrong thing to the wrong collection, like adding to instead of to . Up to now, that bug has been really hard to find, because you only get symptons when you retrieve the contents of , far from the source of the bug.

With generics, you can declare that a certain vector only contains strings (or that a certain set only contains buttons, etc.). You do it like this:



Now is only allowed to contain strings. If you try to add something incompatible, the compiler will squawk. A compile-time bug is a zillion times easier to fix than a run-time bug.

Much much more on this in Chapter 8 of "Complete Java 2 Certification".


-- Phil
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic