Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

quest no static

 
Anvi Dixit
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello

please find below the code.


This code will compile fine but give run time exception. I agree with that but i still believe that there should be a compile time error with this code at line 1, since bm.go() calls method public void go() which is not static.

Also go() calls start() method which is not static . Hence we can't make the line no 2 public static void go() which will give compilation error.

Please let me know the exact problem here


Thanks in advance
Anvi
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you think that there should be a problem with calling non-static methods?

What are the conditions to be satisfied when calling notifyAll (or wait, or notify)? Look at the exception you are getting, you know what it means?
[ March 08, 2007: Message edited by: Barry Gaunt ]
 
Andr� Junior
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you call 'wait','notifyAll' and 'notify', you must have the lock
on the object, otherwise you'll get a 'IllegalMonitorStateException' =]
[ March 08, 2007: Message edited by: Andr� Junior ]
 
Rachil Chandran
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think about it. You are not calling go() from a static context, you are calling go() in bm instance's context
 
Chris Stann
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the book: wait(), notify(), and notifyAll() must be called from within a synchronized context! A thread can't invoke a wait or notify method on an object unless it owns that object's lock. See SCJP book, page 720.
 
Anvi Dixit
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to All,

I understood the problem that while calling the go method (bm.go()) it was called from the bm instance's context and not from the static context and thats why even the go method is non static it's not giving any error.

Thanks again
Anvi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic