Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

uses unsafe or unchecked operations

 
Pauldon
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone have a clue whats going on here i keep getting unchecked or unsafe operations. Tried compiling it in command window. Still dont know what the problem is. Thanks.

 
Scott Dunbar
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, we're missing the code to Move.java but generally casts are not a good idea since the inclusion of generics in the language. You're likely to get better results by doing:

 
Pauldon
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah that has helped thanks, the only problem i have left is with adding a new move. Here is the move class.

Its the move.zplane.add(new Move(n,r,cc)); its not liking.

Sorry to bother you. Cheers.


 
Scott Dunbar
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same problem - declare zplane as:



and you'll be in better shape.

The problem you're having is that things like ArrayList and the other collections always took and returned Object's in 1.4 and below. Now you can strongly type them by specifing that, for example, zplain is an ArrayList of Move objects. Nothing else will be allowed to be put in or returned from the ArrayList. The error and warnings are to let you know that there is a safer way of doing things in Java 1.5/5.0.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your original code will compile without warning using -source 1.4 (and therefore, -target 1.4). Therefore, the question is "which VM are you targetting?" If you are targetting 1.5, you will need to become familiar with 1.5 language features, and in this specific case generics.

If you are not targetting 1.5 - but some lower VM (e.g. 1.4) - then you can delay learning these new language features for now.

Simply, if you are using/targetting 1.5, you need to know what 1.5 is.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tony Morris:
Your original code will compile by warning using -source 1.4 (and therefore, -target 1.4). Therefore, the question is "which VM are you targetting?" If you are targetting 1.5, you will need to become familiar with 1.5 language features, and in this specific case generics.

If you are not targetting 1.5 - but some lower VM (e.g. 1.4) - then you can delay learning these new language features for now.

Simply, if you are using/targetting 1.5, you need to know what 1.5 is.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic