• Post Reply Bookmark Topic Watch Topic
  • New Topic

type casting and variable type

 
Rich Stepanski
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems to make sense to declare variables that never get very large as shorts and bytes. However, it seems by doing this it requires a lot more type casting - at least when setting the variables , it seems everything has to be cast from an integer to the type.

Do these extra type casts make saving space not worth it?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Obviously that depends on whether space or speed is more important in your application! Most narrowing casts (int -> short, for example) compile to a single bytecode; for example, "i2s", which converts an int to a short. Its native implementation is likely quite fast, but still, it is indeed an extra instruction.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to admit that I virtually never use short or byte - mostly because I don't like to think about how large a value could get, all I want to do is store a whole number.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!