为什么布尔在Java中只需真的还是假的?为什么不1或0也? [英] Why boolean in Java takes only true or false? Why not 1 or 0 also?
本文介绍了为什么布尔在Java中只需真的还是假的?为什么不1或0也?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有任何理由为什么Java的布尔只需要真正
或假
为什么不 1
或 0
也?
Is there any reason why Java booleans take only true
or false
why not 1
or 0
also?
推荐答案
Java的,不像在C和C语言++,对待布尔
作为了2个完全独立的数据类型不同的值:true和false。值1和0是int类型,而不是隐式转换为布尔
。
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
.
这篇关于为什么布尔在Java中只需真的还是假的?为什么不1或0也?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文