Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

sleep() method  RSS feed

 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi every body ,
I have one question ,
We know that sleep() is a static method .But I have seen some places Thread.currentThread().sleep() instead of Thread.sleep(), what is the difference between these two ?

Thanks & regards,
S

 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
People who write "Thread.currentThread().sleep()" generally just aren't aware that sleep() is a static method. They believe that they need to fetch the current thread, and call sleep() on it. But since sleep() is static, this is unnecessary, and either line of code will have the exact same effect.
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply ,
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!