LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-10-2005, 09:38 PM   #1
KissDaFeetOfSean
LQ Newbie
 
Registered: Jun 2005
Posts: 27

Rep: Reputation: 15
Unchecked or unsafe operations????


Hi, I am programming under linux and I am reading single-word strings on separate lines of a file and adding them to a TreeSet object. Everything works fine and the TreeSet has the proper items, but I get the following warnings on the command line when I compile:

Note: foo.java uses unchecked or unsafe operations.
Note: Recompile with -xlint:unchecked for details.

Now, I've narrowed it down to the exact lines of code that cause this to happen; here they are:

try {
while ((myStr = in.readLine ()) ! = null)
myTreeSet.add (myStr);
}
catch (IOException e1) {
// blah blah
}
catch (ClassCastException e2) {
// blah blah
}

And this couldnt' possibly be due to my ignoring that boolean val returned when a TreeSet object adds. Please help. Thank you.

Sean
 
Old 09-12-2005, 04:06 PM   #2
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
Java 1.5 supports Generics, which allows you to use Collections and many other classes and stuff such that you can specify all the elements as a certain type (has some similarities with templates in C++). e.g. TreeSet<String> instead of just TreeSet. This allows you to not need to (dangerously) manually cast elements when you retrieve them, allowing it to make typesafe checks at compile time.

This is a very useful feature if you use Java 1.5 (Java before 1.5 doesn't support it). Java 1.5 is backward-compatible in allowing you not to use Generics but complains "unchecked" operations.

Last edited by spooon; 09-12-2005 at 04:28 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unsafe map file Tim Johnson Red Hat 2 10-20-2005 02:08 PM
Unsafe Download Sources? little_penguin Linux - Software 4 03-22-2005 11:39 AM
using scanner 'unsafe' as root irfanhab Slackware 2 08-04-2004 09:38 PM
dmegs tail Unchecked file sysytem -- Run e2fsck Nichole_knc Slackware 6 04-18-2004 05:10 AM
How safe/unsafe is Xvesa? hyper guy Linux - Newbie 3 03-24-2004 07:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration