def third_list[A](ls: List[A]): A = {
// Code can be changed here
return List(ls(2)) //Error line for return type
}
val l1 = List(1, 2, 3, 4)
println(third_list(l1))
println(third_list(List(1,2,(3,4,5), 6, 7)))
I need to return 3rd element of the list following the return type criteria.
I am getting type mismatch error:
Required A found list[A]
Shouldn't ls(2) return an element type already?