• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt in my Java prg

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In one of my java prg based on collections on compliling my IDE(JCreator 2.5 LE) shows following output :-
--------------------Configuration: JDK version 1.5.0 <Default>--------------------
Note: F:\LEARN\JAVA APPS\EXPERIMENTS\CompDemo1.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Process completed.

The programs runs Completely!...no prb with prg just, whats the meaning of it (....i.e "unchecked or unsafe operations" )? B'coz i had never heard of such terms "unsafe" or "unchecked" in Java, they are in C# !

one more thing ......how does the integer value obtained from my userdefined comparator is used by the tree set " EXACTLY! " ?

Can comparison using comparator be only " = ", " <= ", " >= " ?....i mean when we have operators, why is their a separate need of comparators ?

i have some more dbts in Collections (...in java alltogether) , Hope the moderator does not think of my dbts as burst of interview dbts ! Please! Am trying to get deep down in java on my own by refering books and when they are unclear i make a list and ask them, javaranch does not allow me to ask the list of dbts in one thread else...i would have!
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The warning message means that in at least one spot, you're using a Collection in the "old" (before 1.5) way:

ArrayList list = new ArrayList();
list.add("foo");
String s = (String) list.get(0);

This is "unsafe" because of that cast. In Java 1.5, you have generics, which allow you to write this:

ArrayList<String> list = new ArrayList<String>();
list.add("foo");
String s = list.get(0);

Note there is no more cast. Google for "Java generics" to find lots of information on this topic.

As to your second question, the operators you list don't work on Objects, only on numbers, right? So you need Comparators or Comparables to provide ways of comparing Objects.

The integer returned by a Comparator is used by a TreeSet to put objects in order. If the number is positive, one object should come first; if it's negative, then the second should be first. If it's zero, they're the same.
 
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic