• Post Reply Bookmark Topic Watch Topic
  • New Topic

switch  RSS feed

 
Shalini Srivastav
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


char is wider than byte then how it can be passed in byte type of parameter ?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shalini Srivastav wrote:char is wider than byte then how it can be passed in byte type of parameter ?

Almost certainly for the same reason that you can say:
byte b=12;

The '12' is an int, but the compiler is smart enough to know that the value 12 will fit in a byte. Same with 'a'.

Winston
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Back to the Java Language Specification link I posted earlier! you should be able to work out whether the byte can be widened to a char. Try the same block with... instead of the byte declaration.
You can widen anything to an int for a switch-case block.
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or tryYou can widen all your constant expressions after case to ints.
 
Randall Twede
Ranch Hand
Posts: 4696
8
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i guess it is kind of like i write a method that takes a long. it is no problem to pass it an int.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!