Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23
Like Tree1Likes

Thread: why is the most simple thing not working?

  1. #21
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: why is the most simple thing not working?

    Actually, there's no object in sight at all.

  2. #22
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,436
    Blog Entries
    7
    Rep Power
    20

    Default Re: why is the most simple thing not working?

    Quote Originally Posted by diamonddragon View Post
    Actually, there's no object in sight at all.
    Yes there is: the object "blah" exists. It's a literal value stored in the String pool.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #23
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: why is the most simple thing not working?

    So, line 2 is checking reference value, and the rest of code is chacking character sequence of String objects.
    And it's easy to see that equals method is also using if (words == "blah"), when it says: if (this == anObject), but in addition, it has "characters comparision".

    Java Code:
        public boolean equals(Object anObject) {
            if (this == anObject) {
                return true;
            }
            if (anObject instanceof String) {
                String anotherString = (String)anObject;
                int n = count;
                if (n == anotherString.count) {
                    char v1[] = value;
                    char v2[] = anotherString.value;
                    int i = offset;
                    int j = anotherString.offset;
                    while (n-- != 0) {
                        if (v1[i++] != v2[j++])
                            return false;
                    }
                    return true;
                }
            }
            return false;
        }

Page 2 of 2 FirstFirst 12

Similar Threads

  1. How to do a simple class+object thing
    By ilop12 in forum New To Java
    Replies: 8
    Last Post: 06-03-2010, 04:08 PM
  2. please i need help with a simple thing
    By zohdi in forum New To Java
    Replies: 28
    Last Post: 05-30-2010, 01:41 AM
  3. [SOLVED] Simple Trig Thing
    By AndrewM16921 in forum New To Java
    Replies: 4
    Last Post: 05-16-2009, 06:45 AM
  4. Replies: 5
    Last Post: 02-25-2009, 07:14 PM
  5. simple validations not working
    By rahaman.athiq in forum Web Frameworks
    Replies: 0
    Last Post: 11-06-2008, 06:10 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
  •