1

Code:

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

Stack trace:

 javac Ex11.java 
Ex11.java:18: error: cannot find symbol
        a.changeTheHueOfTheColor(newHue = 1);
                                 ^
  symbol:   variable newHue
  location: class Ex11
1 error

What does this mean, and how can I correct it?

halfer
  • 19,824
  • 17
  • 99
  • 186
Michael
  • 4,273
  • 3
  • 40
  • 69
  • 2
    Java does not support "named arguments". If you want to call the method with the value `1`, just write `method(1)`, without the `newHue = `. – Zabuzard Apr 04 '20 at 08:45
  • And that’s not a stack trace. It’s a compiler error. A stack Trace is what you get at runtime. – Axel Apr 04 '20 at 11:53

1 Answers1

5

Java does not have named arguments, just positional arguments. You need to pass it without the parameter's name:

a.changeTheHueOfTheColor(1);
// Here -----------------^
Mureinik
  • 297,002
  • 52
  • 306
  • 350