问题描述
我找不到Java的任何命名约定,都涵盖了不遵循标准“ s”复数形式的单词的用法。
//Given a list of biologies,what should the getter method be?
private List<Biology> biologies;
public Biology getBiology();
public List<Biology> getBiologies();
复数形式有很大不同时的惯例是什么?
//Given a list of octopi,what should the getter method be?
private List<Octopus> octopi;
public Octopus getoctopus();
public List<Octopus> getoctopi();
解决方法
这只是观点,但我称其为“最佳实践”并说:
使用复数形式并正确拼写。
就像您应该正确拼写所有变量/字段一样(如果清楚,可以接受长期缩写词,例如min
,max
等)。
不是权威性的,但是Intellij自动生成正确拼写的复数,例如:
List<Company> x; // "companies" will be auto-suggested if you rename "x"