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

can byte literal be a character literal  RSS feed

 
krishnadhar Mellacheruvu
Ranch Hand
Posts: 118
Android Java Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

as per my knowledge characters literals can be in 4 ways

char ch = 'a';
char ch = 97;
char ch = '\uxxxx'
char ch = 'any of the 8 escape characters';

here my doubt is since character literals take unicode value and unicode representation and display the corresponding character in the console output, when i am using unicode values and unicode representation in integral literals its not giving me any error. cause as per my knowledge integral literals can be of

Decimal
Octal
Hexadecimal

the reason being

int d = 'a';

s.o.p(d);

this is not giving me an error but instead displaying the unicode value i.e. 97

similarly

int d = '\uFace';

s.o.p(d);

this is giving me 64206 instead of an error



 
Paweł Baczyński
Bartender
Posts: 2054
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The value of char type is just a number (0 - 65535).
It can always be assigned to int variable.
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also denominate them in binary (Java7+).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!