Compilation error: type "empty" not allowed here

advertisements

How can I resolve this type of a compilation error.

The bold part is the place where it shows a compilation error.

DegreeDays.java:71: 'void' type not allowed here
        System.out.println(***"\t"***(error here) +
            list(test[counter]) + "\t\t\t" +
            average_temp(test[counter], test[counter - 1]));

DegreeDays.java:71: 'void' type not allowed here
        System.out.println("\t" + list(test[counter]) ***+
            ***(error here) "\t\t\t" +
            average_temp(test[counter], test[counter - 1]));


Imagine this:

void foo() {
  // doesn't matter
}

System.out.println("" + foo()); // What should happen here?

The answer is explode - and this is what javac is correctly doing. The method foo has a "void result type" (none, nada, zilch). There is no object returned. Ever. Not even null. There is "nothing" and the compiler will refuse to try and use "nothing" as a "something".

(A method with a "void result type" is different than a method which can return null -- e.g. return type is Object - such a method still has a "non-void" result type.)

Happy coding.