gpt4 book ai didi

java - 你能解释一下 Java 中的 "isXxx"方法名吗?

转载 作者:搜寻专家 更新时间:2023-10-30 21:36:37 29 4
gpt4 key购买 nike

是否在其中一个规范中引用了以“is”开头的方法,而方法名称的后缀是属性名称(类似于 Java bean 的 getter/setter 方法)?

例如:

public boolean isConditionTrue() {
...
...
}

private boolean conditionTrue;

谢谢!

最佳答案

这是 Java 命名约定,

If the method returns a boolean value, use is or has as the prefix for the method name. For example, use isOverdrawn or hasCreditLeft for methods that return true or false values. Avoid the use of the word not in the boolean method name, use the ! operator instead. For example, use !isOverdrawn instead of isNotOverdrawn.

另见:


根据Java语言规范,

A method that tests a boolean condition V about an object should be named isV. An example is the method isInterrupted of class Thread.

关于java - 你能解释一下 Java 中的 "isXxx"方法名吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7155491/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com