Christopher White
Christopher White

Reputation: 39

comparing object calling the method

i know this is very trivial, but for some reason i'm having a little trouble. i'm trying to write a method that has a book object from an array list calling the method that compares it to another book in the same list. I think i got the gist of it but i'm just not understanding how to compare them. i think it's supposed to look something like this.

 public Boolean isShorter(Book otherBook)
 { 
    if(otherBook.getLength() < ???????.getLength() )
          return true;
    else  
          return false;
}   

Upvotes: 0

Views: 41

Answers (1)

Imbar M.
Imbar M.

Reputation: 1114

use "this" keyword to refer to the current object (the caller of the method). like this:

otherBook.getLength() < this.getLength()

Upvotes: 2

Related Questions