Why boolean in Java takes only true or false? Why not 1 or 0 also?

后端 未结 8 1141
太阳男子
太阳男子 2020-12-01 05:28

Is there any reason why Java booleans take only true or false why not 1 or 0 also?

8条回答
  •  悲哀的现实
    2020-12-01 05:29

    Java, unlike languages like C and C++, treats boolean as a completely separate data type which has 2 distinct values: true and false. The values 1 and 0 are of type int and are not implicitly convertible to boolean.

提交回复
热议问题