Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of these is the correct way to sleep using a TimeUnit?

  • A.TimeUnit.sleep(5, SECONDS);
  • B.Thread.SECONDS.sleep(5);
  • C.TimeUnit.SECONDS.sleep(5);
  • D.Thread.sleep(5, TimeUnit.SECONDS);

Answer: C

The enum constant itself carries a sleep method, so the unit reads before the duration and no conversion is written by hand. Thread.sleep has no TimeUnit overload, which is why the enum form is often preferred for readability.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.