gpt4 book ai didi

java - 与 Java 中的类同名的对象

转载 作者:行者123 更新时间:2023-11-30 03:44:11 30 4
gpt4 key购买 nike

CoordinateArray coordinateArray, coordinateArray1, coordinateArray2;
FileCopy fileCopy, fileCopy1, fileCopy2;

CoordinateArray c_arr, c_arr_1, c_arr_2;
FileCopy f_copy, f_copy_1, f_copy_2;

在编写 C 语言时,我肯定会选择后者,但最近在编写一些 Java 代码时,我很想选择第一种。无论出于何种原因,Java 中首选哪种方式,或者第一种方式命名变量“可以”吗?我专门询问 Java,因为我想遵循该语言的约定。

最佳答案

可读性和驼峰命名法是 Java 中的约定。

来自官方文档:

Variables:

Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed.

Variable names should be short yet meaningful. The choice of a variable name should be mnemonic- that is, designed to indicate to the casual observer the intent of its use. One-character variable names should be avoided except for temporary "throwaway" variables. Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for characters.

以下是 Oracle 命名约定存档版本的链接:http://www.oracle.com/technetwork/java/codeconventions-135099.html

关于java - 与 Java 中的类同名的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26152538/

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