java-当我们在类名中使用“ iOS”作为单词时,是否应该将“ i”大写?

某些品牌名称实际上并不喜欢使用首字母大写,更改名称可能会使外观看起来完全不同,尤其是对于“ iOS”而言.还有更多类似“ mCore”,“ macOS”等等.关于班级名称,我应该将首字母大写还是保留原样?

例如“ iOSCompatProxy”和“ IOSCompatProxy”

最佳答案
对于这种类型的类名,没有普遍遵循的约定.甚至常规的大写缩写(如“ XML”)也会导致不一致.从the official JDK class list来看,我看到与XmlSomething一样多的名为XMLSomething的类.

Google在Google Java Style Guide中处理了这个主题,他们提出了一种将文本转换为类名的方案:

Sometimes there is more than one reasonable way to convert an English phrase into camel case,such as when acronyms or unusual constructs like “IPv6” or “iOS” are present. To improve predictability,Google Style specifies the following (nearly) deterministic scheme.

Beginning with the prose form of the name:

  1. Convert the phrase to plain ASCII and remove any apostrophes. For example,“Müller’s algorithm” might become “Muellers algorithm”.

  2. Divide this result into words,splitting on spaces and any remaining punctuation (typically hyphens).

    • Recommended: if any word already has a conventional camel-case appearance in common usage,split this into its constituent parts (e.g.,“AdWords” becomes “ad words”). Note that a word such as “iOS” is not really in camel case per se; it defies any convention,so this recommendation does not apply.
  3. Now lowercase everything (including acronyms),then uppercase only the first character of:

    • … each word,to yield upper camel case,or
    • … each word except the first,to yield lower camel case
  4. Finally,join all the words into a single identifier.

他们的方案产生IosCompatProxy作为类名,并产生iosCompatProxy作为变量名.他们故意不理会原始大写字母,而是采用基于规则的骆驼案形式.

也许这不是最漂亮的表格,但是如果您正在寻找可以遵循的规则,并且在您工作的地方没有规则,那么Google的风格指南将是您的最佳选择,因为它专门提到“ iOS”.我倾向于高度重视他们的约定,因为他们使用它们维护着大量Java(截至2018 [1]为止有3亿行).

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


应用场景 C端用户提交工单、工单创建完成之后、会发布一条工单创建完成的消息事件(异步消息)、MQ消费者收到消息之后、会通知各处理器处理该消息、各处理器处理完后都会发布一条将该工单写入搜索引擎的消息、最终该工单出现在搜索引擎、被工单处理人检索和处理。 事故异常体现 1、异常体现 从工单的流转记录发现、
线程类,设置有一个公共资源 package cn.org.chris.concurrent; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; /** * @Descrip
Java中的数字(带有0前缀和字符串)
在Java 9中使用JLink的目的是什么?
Java Stream API Filter(过滤器)
在Java中找到正数和负数数组元素的数量
Java 9中JShell中的不同启动脚本是什么?
使用Java的位填充错误检测技术
java中string是什么
如何使用Java中的JSON-lib API将Map转换为JSON对象?
Java菜单驱动程序以检查数字类型
使用Junit的Maven项目 - 检查银行账号
JAVA编程基础
在Java中使用throw、catch和instanceof来处理异常
在Java中,将数组分割为基于给定查询的子数组后,找到子数组的最大子数组和
如何在Java中从给定的字符串中删除HTML标签?
在PHP中,IntlChar getBlockCode()函数的翻译如下:
如何在Android中实现按下返回键再次退出的功能?
如何使用Java中的流式API解析JSON字符串?
Java中的模式类