As mentioned in the comments, the fact that you return within your map, cause you to not get your expected result. A quote from The Point of No Return that @LuisMiguelMejíaSuárez linked in the comments:
A return expression, when evaluated, abandons the current computation and returns to the caller of the method in which return appears.
Therefore you get this warning.
Similar to your code that works is:
case class HttpHost(host: String, port: Int, protocol: String)
val httpHosts = stringHosts.map(host => {
val hostAndPort = host.split(":")
HttpHost(hostAndPort(0), hostAndPort(1).toInt, "http")
})
Having said that, I'd write it the following:
val httpHosts1 = stringHosts.map(_.split(":")).collect {
case Array(host, port) if port.toIntOption.isDefined =>
HttpHost(host, port.toInt, "http")
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…