Reputation: 455
I have a method that runs when there is no specified return type, but as soon as the return type is added, a mismatch error is given. The return type of the returned value is the same.
This works fine:
def get_csv_page(url: String){
scala.io.Source.fromURL(url).getLines.drop(1).toList
}
Returns:
res2: List[String]
But adding : List[String] causes mismatch:
def get_csv_page(url: String) = List[String]{
scala.io.Source.fromURL(url).getLines.drop(1).toList
}
:12: error: type mismatch;
found : List[String]
required: String
scala.io.Source.fromURL(url).getLines.drop(1).toList
^
Upvotes: 0
Views: 93
Reputation: 18187
This is a syntax error, it should be a :
to specify the return type and then an =
:
def get_csv_page(url: String): List[String] = {
scala.io.Source.fromURL(url).getLines.drop(1).toList
}
What you have right now is trying to construct a List literal, which is why it is wanting you to provide a single String for an element of your list.
Upvotes: 4