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

problem with int and long  RSS feed

 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
final int i0=20; short s0=i; //example1

final int i1=33; byte b1=i1; //example2

final long l2=123;int i2=l; //example3

example1 and example2 works fine but for example3 compiler gives error.i know that for example1 value of s0 is in range and also final,so is true for example2.i also know that default of integer is int .but when i tryed same for example3 compiler gives error.i dont know why.
 
Ramakrishna Nalla
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you write that complex looking code just use simple variable names..
Reformat your program and post that one with your error..then you will get quick reply....
 
Shyam Prasad Murarka
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the third example you are trying to assign the int variable with a variable called "l". Whereas, the name of your variable is "l2".
 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes those names are horrendous. Hard to tell what you're trying to do. Looks like maybe in the third example you're trying to squeeze a long into an int?
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Hentay Duke:
Yes those names are horrendous. Hard to tell what you're trying to do. Looks like maybe in the third example you're trying to squeeze a long into an int?


But in the first two examples, the OP is successfully "squeezing" an int into a byte and short respectively. I'm not exactly sure why these two don't generate compiler errors. Hmmm...I'll have to look into this.

Layne
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by gowher amin naik:
hi
final int i0=20; short s0=i; //example1

final int i1=33; byte b1=i1; //example2

final long l2=123;int i2=l; //example3

example1 and example2 works fine but for example3 compiler gives error.i know that for example1 value of s0 is in range and also final,so is true for example2.i also know that default of integer is int .but when i tryed same for example3 compiler gives error.i dont know why.

Can you post the exact error message? I have an idea of what it is, but I'm confused why the first two examples DON'T give any errors. I'll refrain from elaborating until you post the error message so I know for sure if I'm on the right track.

Layne
 
Shyam Prasad Murarka
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read the message I have posted before??
I have clearly stated that the name of the long variable is "l2" whereas initializing int variable i2 you use the variable "l" which does not exist.
 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Did you read the message I have posted before??
I have clearly stated that the name of the long variable is "l2" whereas initializing int variable i2 you use the variable "l" which does not exist."

I was guessing that was a typo in the thread. If you look closely he did the same thing in example one and claims it worked fine!

"final int i0=20; short s0=i; //example1"


[ May 05, 2005: Message edited by: Hentay Duke ]
[ May 05, 2005: Message edited by: Hentay Duke ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shyam Murarka:
Did you read the message I have posted before??
I have clearly stated that the name of the long variable is "l2" whereas initializing int variable i2 you use the variable "l" which does not exist.


That's exactly why I asked for the OP to post the error message. This might be a typo in the post and not the actual code being compiled. Some people need to learn how to use copy and paste in order to avoid such problems.

Layne
 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If he copied and pasted then example 1 shouldn't have worked either. Either way the OP hasn't bothered to check back in so we may never know.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!