Results 1 to 7 of 7
- 03-30-2011, 07:30 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 10
- Rep Power
- 0
Method/If Statement, dereference error
im trying to perform this method/if statement
however when i try and compile it saysJava Code:private void displayCurrentPlayer(int currentPlayer) { if (currentPlayer.equals(USER_NUMBER)) { System.out.println("Computer's turn to play."); } else { System.out.println("User's turn to play."); } }
Any suggestions/help???Java Code:A1Stage02.java:193: int cannot be dereferenced if (currentPlayer.equals(USER_NUMBER)) { ^ 1 error
Much appreciated thanks.
- 03-30-2011, 07:32 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
.equals compares strings, numbers are compared with ==.
- 03-30-2011, 07:36 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 10
- Rep Power
- 0
awesome cheers mate!
- 03-30-2011, 08:13 AM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
You are welcome, please mark your thread solved with the thread tools at the top.
- 03-30-2011, 09:04 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
- 03-30-2011, 09:07 AM #6
And primitives OR references can be compared with ==
db
- 03-30-2011, 09:29 AM #7
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
"The equals method for class Object implements the most discriminating possible equivalence relation on objects" but is overridden however a class thinks fit so long as it "implements an equivalence relation on non-null object references".
Equivalence leaves rather a lot of arbitrary wiggle room: things can be quite different and yet be considered equal. As Anatole France observed, "The law, in its majestic equality, forbids the rich as well as the poor to sleep under bridges, to beg in the streets, and to steal bread".
Similar Threads
-
method return statement is wrong
By ftrengnr in forum New To JavaReplies: 1Last Post: 10-19-2010, 04:15 AM -
how to store into array.char cannot dereference
By dark_metal in forum New To JavaReplies: 9Last Post: 04-05-2010, 07:40 PM -
giving missing return statement error.due to withdraw method.
By qadeer37 in forum New To JavaReplies: 5Last Post: 01-16-2010, 11:14 PM -
Missing return statement help and format method help
By Chewart in forum New To JavaReplies: 18Last Post: 12-02-2009, 12:01 PM -
Method in a Switch Statement
By cart1443 in forum New To JavaReplies: 6Last Post: 03-14-2008, 03:48 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks