Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Long  RSS feed

 
Manish Khurana
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why dooes this work i though it had to have a L at the end
long patience = 1000 * 60 * 60;
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without an L, the result is an integer, because all operands are integers. Since 1000 * 60 * 60 (3600000) is a valid integer, there will be no problems.

If your intermediate result would exceed Integer.MAX_VALUE (2^31-1), then the result would be truncated, and you would get a wrong value. Only then you need an L to inform the compiler that the intermediate result is a long as well so it won't be truncated.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!