Here is my code and I actually do not need any return values and types, and wondering how to handle this error?
Error of "overload method needs result type" is on this line foo (start, end, 14)
object HelloWorld {
def foo(start: String, end: String) = {
foo (start, end, 14)
}
def foo(start: String, end: String, id: Int) = {
println("Hello, world!")
}
def main(args: Array[String]): Unit = {
foo("hello", "scala")
}
}
Corrected version of code,
object HelloWorld {
def foo(start: String, end: String): Unit = {
foo (start, end, 14)
}
def foo(start: String, end: String, id: Int): Unit = {
println("Hello, world!")
}
def main(args: Array[String]): Unit = {
foo("hello", "scala")
}
}
thanks in advance, Lin
Here is my code and I actually do not need any return values and types, and wondering how to handle this error?
You do. Scala doesn't allow you to have two foo
methods without specifying return types (both Unit
in this case).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With