用户登录
用户注册

分享至

为什么Java中的布尔值只接受真或假?为什么不是 1 或 0 呢?

  • 作者: 孤寂de心
  • 来源: 51数据库
  • 2022-12-09

问题描述

Java 布尔值仅采用 true 或 false 为什么不采用 1 或 0 有什么原因吗?

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

推荐答案

Java 与 C 和 C++ 等语言不同,将 boolean 视为完全**的数据类型,具有 2 个不同的值:true 和 false.值 1 和 0 是 int 类型,不能隐式转换为 boolean.

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相关