We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
One of the Type Ascription hint-questions is:
Is it a recursive or overloaded methods return value? Yes, you have to.
It's easy to prove this for recursive methods:
scala> class SumMaker { | def sum(ints: List[Int]) = ints match { | case Nil => 0 | case x :: tail => x + sum(tail) | } | } <console>:40: error: recursive method sum needs result type case x :: tail => x + sum(tail) scala> class SumMaker { | def sum(ints: List[Int]): Int = ints match { | case Nil => 0 | case x :: tail => x + sum(tail) | } | } defined class SumMaker scala> val a = new SumMaker a: SumMaker = SumMaker@545d7e85 scala> a.sum(List(1,2,3,4) | ) res3: Int = 10
But overloaded methods do not seem to require an ascribed return type:
scala> class Overloader { | def overloaded(x: Int) = { x } | def overloaded(x: String) = { x } | } defined class Overloader scala> val x = new Overloader() x: Overloader = Overloader@10bdc63a scala> x.overloaded("1") res2: String = 1 scala> x.overloaded(1) res3: Int = 1
Did I miss something? Or is ascribing the overloaded method's return value a recommendation rather than a requirement?
The text was updated successfully, but these errors were encountered:
No branches or pull requests
One of the Type Ascription hint-questions is:
It's easy to prove this for recursive methods:
But overloaded methods do not seem to require an ascribed return type:
Did I miss something? Or is ascribing the overloaded method's return value a recommendation rather than a requirement?
The text was updated successfully, but these errors were encountered: