Java 将命名参数传递给方法

Java 将命名参数传递给方法,java,arguments,syntax-error,named-parameters,Java,Arguments,Syntax Error,Named Parameters,代码: 堆栈跟踪: class AllTheColorsOfTheRainbow { private int hue = 0; int anIntegerRepresentingColors; void changeTheHueOfTheColor(int newHue) { this.hue = newHue; } public int getHue(){ return this.hue; } }

代码:

堆栈跟踪:

class AllTheColorsOfTheRainbow {
    private int hue = 0;

    int anIntegerRepresentingColors;    

    void changeTheHueOfTheColor(int newHue) {
        this.hue = newHue;
    }

    public int getHue(){
        return this.hue;
    }
}

public class Ex11 {
    public static void main(String [] args){
        AllTheColorsOfTheRainbow a = new AllTheColorsOfTheRainbow();
        a.changeTheHueOfTheColor(newHue = 1);
        System.out.println(a.getHue());
    }
}

你能帮我理解它是什么意思以及如何纠正它吗

Java没有命名参数,只有位置参数。您需要在不使用参数名称的情况下传递它:

a.改变颜色的颜色(1);
//这里-----------------^

Java没有命名参数,只有位置参数。您需要在不使用参数名称的情况下传递它:

a.改变颜色的颜色(1);
//这里-----------------^

Java不支持“命名参数”。如果要使用值
1
调用方法,只需编写
method(1)
,而不使用
newHue=
。这不是堆栈跟踪。这是一个编译器错误。堆栈跟踪是您在运行时得到的。Java不支持“命名参数”。如果要使用值
1
调用方法,只需编写
method(1)
,而不使用
newHue=
。这不是堆栈跟踪。这是一个编译器错误。堆栈跟踪是您在运行时得到的。
 javac Ex11.java 
Ex11.java:18: error: cannot find symbol
        a.changeTheHueOfTheColor(newHue = 1);
                                 ^
  symbol:   variable newHue
  location: class Ex11
1 error