MCQs > IT & Programming > Scala > Choose correct statement which solves the error when you remove the line implicit

Scala MCQs

For the code fragment below

object Main extends App { def mySum[T <: Number](as: T*): Double = as.foldLeft(0d)(_ + _.doubleValue) implicit def intToInteger(n: Int): Integer = new Integer(n.toInt) var r = mySum(2, 3) }

When complied produces the following error, Choose the correct statement which solves the error when you remove the line implicit def intToInteger(n: Int): Integer = new Integer(n.toInt) Main.scala:4: error: inferred type arguments [Int] do not conform to method mySum's type parameter bounds [T <: Number] var r = mySum(2, 3) ^

Answer

Correct Answer: def mySum[T <% Number](as: T*): Double = as.foldLeft(0d)(_ + _.doubleValue)

Explanation:

Note: This Question is unanswered, help us to find answer for this one

Scala Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it

search

Scala Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it