• Post Reply Bookmark Topic Watch Topic
  • New Topic

Do cast from int to short  RSS feed

 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there, please could you see my code and tell me why I must also do cast of rangeDe5NumeroNoMaximo attribute
because that atributte also short typed...



thanks,
André AS
SP - Brazil
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello to you David,

I joined your web link...

I read that the default value of long is 0L, ok but I can't use it right? Look at:



That shows compile-time error, why?


André AS
São Paulo - Brazil
 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should not that print their default value?

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
André Asantos wrote:Should not that print their default value?

Local variables inside methods, as you show in your example, do not have default values. You must initialize them to a value before you use them.

Only member variables (at the level of a class) are initialized with default values (0L in the case of a long).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!