Java 布尔吸气剂“是"vs“是"

Java boolean getters quot;isquot; vs quot;arequot;(Java 布尔吸气剂“是vs“是)

本文介绍了Java 布尔吸气剂“是"vs“是"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 Java 中布尔 getter 的约定是包含前缀is".

I know that the convention in Java for boolean getters is include the prefix "is".

isEnabled
isStoreOpen

但是如果主语是复数呢?也就是说,如果我不想知道一家商店是否营业,而是想知道所有商店是否都营业,该怎么办?

But what if the subject is plural? That is, what if instead of wanting to know if a store is open, I wanted to know if all the stores are open?

isStoresOpen() 在英文中没有意义.

我很想写像这样的吸气剂:

I'm tempted to write getters like:

areStoresOpen
areDogsCute
areCatsFuzzy

我认为这是有道理的,但其他人告诉我,我应该接受它并放弃主语动词协议并使用 isStoresOpenisDogsCute, isCatsFuzzy.

And I think that would make sense, but I've been told by others that I should just suck it up and abandon subject verb agreement and use isStoresOpen, isDogsCute, isCatsFuzzy.

无论如何,对于在复数主题上操作的布尔 getter,我应该怎么做?

Anyway, what should I do for boolean getters which operate on a plural subject?

推荐答案

我不记得这是出自哪本书,但本质是代码的阅读次数比编写次数要多得多.为了可读性而写.

I can't remember which book this was from, but the essence is that code will be read many more times than it's written. Write for readability.

这篇关于Java 布尔吸气剂“是"vs“是"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Java 布尔吸气剂“是"vs“是"

基础教程推荐