• Post Reply Bookmark Topic Watch Topic
  • New Topic

public boolean equals ()  RSS feed

 
N Kol
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have:

public boolean equals(pkgType that)
{
if (this.pkgType== that.pkgType)

return true;

the pkgType is sytaxing. pkgType is a decleared variable. Not sure what to do here, can anyone help?
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't completely understand your question, but in your example pkgType would have to be the name of a class (which you should actually capitalize) and the name of a member variable in that class. You have a return value in the case this.pkgType == that.pkgType, but no return value if they aren't equal. That would cause a compile error, which might be what you mean when you say it is "syntaxing". What you need is something like: else return false.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add this is not an override of the equals method. Just a specialization. The equals method has an Object reference as parameter and should check is it's from the same class and check for null values.
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at this FAQ, and look for no 28.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!