JAVA:不是声明 - 用于调用 'long'?
JAVA: Not a statement - for calling 'long'?
下面这段代码是我写的
public long secFromMidnight()
{
long seconds_from_midnight = (this._hour * SEC_IN_HOUR) + (this._minute * SEC_IN_MIN) + (this._second);
return seconds_from_midnight;
}
public int difference(Time1 other)
{
long 1stSEC = null;
long 2ndSEC = null;
1stSEC= this.secFromMidnight();
2ndSEC = other.secFromMidnight();
return (int)(1stSEC - 2ndSEC);
}
当我尝试编译时,"long 1stSEC = null";
出现 "Not a Statement" 错误
为什么会这样?
我之前可以在方法中声明一个long变量..
变量的名称不能以数字开头。
Variable names are case-sensitive. A variable's name can be any legal
identifier — an unlimited-length sequence of Unicode letters and
digits, beginning with a letter, the dollar sign "$", or the
underscore character "". The convention, however, is to always begin
your variable names with a letter, not "$" or "".
Java variables' naming conventions
此外,long
是一个 原始类型 ,因此您不能将 null
分配给 long
变量。将其设置为 0。
用正确的名称重命名这些变量,而不是用 null
初始化它们,而是用 0
初始化它们,例如:
long sEC1st = 0;
long sEC2nd = 0;
Using ALL uppercase letters are primarily used to identify constant variables. Remember that variable names are case-sensitive. You cannot use a java keyword (reserved word) for a variable name.
下面这段代码是我写的
public long secFromMidnight()
{
long seconds_from_midnight = (this._hour * SEC_IN_HOUR) + (this._minute * SEC_IN_MIN) + (this._second);
return seconds_from_midnight;
}
public int difference(Time1 other)
{
long 1stSEC = null;
long 2ndSEC = null;
1stSEC= this.secFromMidnight();
2ndSEC = other.secFromMidnight();
return (int)(1stSEC - 2ndSEC);
}
当我尝试编译时,"long 1stSEC = null";
出现 "Not a Statement" 错误为什么会这样? 我之前可以在方法中声明一个long变量..
变量的名称不能以数字开头。
Variable names are case-sensitive. A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign "$", or the underscore character "". The convention, however, is to always begin your variable names with a letter, not "$" or "".
Java variables' naming conventions
此外,long
是一个 原始类型 ,因此您不能将 null
分配给 long
变量。将其设置为 0。
用正确的名称重命名这些变量,而不是用 null
初始化它们,而是用 0
初始化它们,例如:
long sEC1st = 0;
long sEC2nd = 0;
Using ALL uppercase letters are primarily used to identify constant variables. Remember that variable names are case-sensitive. You cannot use a java keyword (reserved word) for a variable name.