• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Missing Numeric Suffixes

 
Joshua Smith
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why aren't there numeric suffices for byte, short or int? By numeric suffices I mean the letters that you attach to a number to coerce it into being a specific type of primitive literal (e.g. 2L to mean "2 as a long"). The lack of a numeric suffix for int kind of make sense as int is the default for integral numbers, but then consistency would seem to indicate that there wouldn't be one for double since double is the default for floating point literals. And why would byte and short be left out?

I'm not sure how important the answer to this question is to certification, but I'm wondering if there's something about the numeric primitives that I'm missing that would make the answer obvious.

Thanks,
Josh
 
Thomas Paul Bigbee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its because floating point literals (0.1, 122.32, etc...) are automatically considered as doubles, so float x = 0.1 would cause a compile time error, where as with bytes, shorts, chars, ints and longs, this would work with all of them - byte x = 1, short x = 1, etc..., its just the way the spec was written.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic