无法在方法中创建实例的其他引用

时间:2014-09-23 20:53:40

标签: java methods reference

我在Eclipse中制作计算器程序作为excersize。我收到很多错误。我想做的是"更改名称"在两个引用thisdec中,以使代码在后面的方法中更加清晰。有什么问题?

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;
    }

1 个答案:

答案 0 :(得分:3)

shortlong是关键字。您不能将它们用作变量名称。 shortestlongest没问题。