• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Javarules Roundup #125

 
Ranch Hand
Posts: 330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all. just took javarules roundup and....
Question states: Can you automatically/implicitly convert a char to a short?
Answer given is no. They're the same bit-depth but since chars are unsigned, they might have a higher positive value than a short can accept.
Comment: I can automatically / implicitly convert a char to a short if the char variable is declared final and value not more than short's allowable maximum value. The code below when placed in a method and class compiles just fine.

Am i not reading the question right?
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the question reffers implicitly to variables...
when you decared final char ...
you are dealing with a constant so not a variable but a value so its known at compile time) thats why u don't get a compile error
(value 3 is OK wihin range)
to better understand try the values 32767 (compiles since is last valid value for short) and 32768 (error) with you final char definition
 
dennis zined
Ranch Hand
Posts: 330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Dan.
 
Pay attention! Tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic