2

I am new to Java and I read in a book Java supports automatic promotion and when I assigned a Boolean value to int it gives error Now my question is since Boolean is one bit and int is 4 byte, it should get promoted but then why does it give me an error ?

Raedwald
  • 46,613
  • 43
  • 151
  • 237
user4380889
  • 31
  • 1
  • 4

1 Answers1

3

Boolean is not a numeric type. Promotion only applies to compatible types.

lared
  • 1,934
  • 1
  • 13
  • 16
  • How come Boolean is not a numeric type ? It stores either 1 or 0 so it should be a numeric type – user4380889 Jan 07 '15 at 13:06
  • Actually it stores either `true` or `false`. Nowhere in the standard it says that it's `0` or `1`. [See here](http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.5). An integer can be converted to a boolean value, but not the other way. – lared Jan 07 '15 at 13:13