简体   繁体   English

Java:方法名称约定

[英]Java: Method name conventions

This is more out of curiosity than anything else, just wondering what are the most common naming conventions for method names? 这是出于好奇,而不是出于其他原因,只是想知道方法名称最常用的命名约定是什么?

Start with a capital 从资本开始

GetName() 

or start lowercase and then capitals for each new word 或以小写开头,然后每个大写字母大写

getName()

or something else. 或者是其他东西。

Java uses camelCase convention for method names. Java对方法名称使用camelCase约定。

You can read more about conventions in Java in this document: Code Conventions for the Java Programming Language 您可以在本文档中阅读有关Java约定的更多信息: Java编程语言的代码约定

In Java, the convention is to have the first word with a lower case, and the rest with upper case. 在Java中,约定是第一个单词用小写字母,其余单词用大写字母。

public void getName()

Also, constants are declared in full capitals: 另外,常量以全大写字母声明:

public final int MAX_USERS

In Java, the naming convention for methods is getName() 在Java中,方法的命名约定为getName()

Variables also follow the same naming convention as methods, for example. 例如,变量也遵循与方法相同的命名约定。 getNameExample getNameExample

The naming convention used for classes capitalizes every word ex. 用于类的命名约定将ex的每个单词大写。 GetName 取名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM