Java方法名称的有效字符是什么? [英] What are the valid characters for a Java method name?

查看:158
本文介绍了Java方法名称的有效字符是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到了有关 Java变量命名的信息。它说除了$和_之外,Java变量不能以任何数字和特殊字符开头。

I read about the naming of Java variables. It says that Java variables cannot start with any numbers and special characters except for $ and _.

一些有效的例子:

int count;
int _count;
int $count;

以及一些无效的例子:

int %count;
int 4count;
int #count;

相同的规则是否适用于方法名称?

Do the same rules apply to method names?

推荐答案

是的,方法名称和变量名称就是所谓的标识符。标识符共享有关接受字符的相同规则。看看§3.8从Java语言规范中找出标识符可能包含的内容,并且§6.2有关如何使用标识符的说明。

Yes, method names and variable names are what's called "identifiers". Identifiers all share the same rules regarding accepted characters. Take a look at §3.8 from the Java Language Specification to find out exactly what an identifier may contain, and §6.2 for an explanation about how identifiers are used.

这篇关于Java方法名称的有效字符是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆