Results 1 to 7 of 7
  1. #1
    scottmulla is offline Member
    Join Date
    Mar 2011
    Posts
    10
    Rep Power
    0

    Exclamation Method/If Statement, dereference error

    im trying to perform this method/if statement

    Java 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.");
    		}
    	}
    however when i try and compile it says

    Java Code:
    A1Stage02.java:193: int cannot be dereferenced
    		if (currentPlayer.equals(USER_NUMBER)) {
    		                 ^
    1 error
    Any suggestions/help???
    Much appreciated thanks.

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    .equals compares strings, numbers are compared with ==.

  3. #3
    scottmulla is offline Member
    Join Date
    Mar 2011
    Posts
    10
    Rep Power
    0

    Default

    awesome cheers mate!

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You are welcome, please mark your thread solved with the thread tools at the top.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default

    Quote Originally Posted by sunde887 View Post
    .equals compares strings, numbers are compared with ==.
    To be more precise, equals() compares Objects.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    And primitives OR references can be compared with ==

    db

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    "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

  1. method return statement is wrong
    By ftrengnr in forum New To Java
    Replies: 1
    Last Post: 10-19-2010, 04:15 AM
  2. how to store into array.char cannot dereference
    By dark_metal in forum New To Java
    Replies: 9
    Last Post: 04-05-2010, 07:40 PM
  3. Replies: 5
    Last Post: 01-16-2010, 11:14 PM
  4. Replies: 18
    Last Post: 12-02-2009, 12:01 PM
  5. Method in a Switch Statement
    By cart1443 in forum New To Java
    Replies: 6
    Last Post: 03-14-2008, 03:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •