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

((long) int)  RSS feed

 
Reshma Reddy
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
can anybody tell me what is mean by ((long) 4) what that int value 4 .what is difference between ((long)4)and ((long)1).

Ragerds,
vishnu.
 
Kail Limas
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I'm understanding you correctly, you have an int value of 4. Now you want to change the int into a long, so you cast your int to a long that's done the way you described: ((long) 4). You know have a long with the number 4. If you type ((long) 1) you have a long with the number 1. In this case it's not necesarry though, because long automaticaly converts an int into a long. The other way around isn't possible though.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16026
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java regards literal numbers in source code as int values. If you need a literal long, then there are two ways to do that:

1. Cast the literal int to a long, which your example shows: (long) 4
2. Append a letter "L" after the number: 4L
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!