Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need answers

 
Vinay Gangoli
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i have some qs i cant find reliable ansswers too...
1) if i dont enclose the wait(), notify(), and notifyall() functions within synchronized loop...what do i get?. Compile time error or runtime error ?
2) I read that i cant just override
boolean equals(object o)and get away with it. That is i have to override hashCode() too. But i just did. I am a bit confused. Comments please.
3)can i have static variables inside of anonymous/method local innerclasses ?
answres to any of these will help me a lot...thanks in advance
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) if i dont enclose the wait(), notify(), and notifyall() functions within synchronized loop...what do i get?. Compile time error or runtime error ?
Runtime. Specifically IllegalMonitorStateException.
2) I read that i cant just override boolean equals(object o)and get away with it. That is i have to override hashCode() too. But i just did. I am a bit confused. Comments please.

It's OK so long as you don't use a HashMap or Hashtable since they use the hashcode to determine unique keys. But you really should override hashCode() any time you override equals(). Specifically: If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.

3)can i have static variables inside of anonymous/method local innerclasses ?

Nope.
 
Vinay Gangoli
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael...that helped...Vinay
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic