Java 无法在方法中创建实例的其他引用
我正在用Eclipse制作一个计算器程序作为练习。我犯了很多错误。我想做的是更改this和dec这两个引用的名称,以便在方法的后面使代码更加清晰。有什么问题Java 无法在方法中创建实例的其他引用,java,methods,reference,Java,Methods,Reference,我正在用Eclipse制作一个计算器程序作为练习。我犯了很多错误。我想做的是更改this和dec这两个引用的名称,以便在方法的后面使代码更加清晰。有什么问题 public Decimals plus(Decimals dec) { //let's get the length of the 2 numbers int this_len=this.getLength(), dec_len=dec.getLength(); int longest_len; //to
public Decimals plus(Decimals dec) {
//let's get the length of the 2 numbers
int this_len=this.getLength(), dec_len=dec.getLength();
int longest_len;
//to simplify the code the two numbers are called long or short
Decimals short; //shortest <-- Syntax error on token 'short', ++ expected / Decimals cannot be resolved to a variable
Decimals long; //longest <-- Syntax error on token 'long', ++ expected / Decimals cannot be resolved to a variable
if (this_len >= dec_len){
short = dec; // <-- Syntax error on token "=", delete this token / Duplicate local variable dec
long = this; // <-- Syntax error on token "long", invalid Expression
longest_len = this_len;
}
else {
short = this; // <-- Syntax error on token "short", VariableDeclaratorId expected after this token
long = dec; // <-- Syntax error on token "long", invalid Expression
longest_len = dec_len;
}
短和长是关键词。不能将它们用作变量名。最短和最长都可以。short和long是基本类型。不能将原语用作变量名称短和长是Java中的关键字。它们是语言保留的,您不能将它们用作变量名。谢谢,我从未想过这一点