Why do I get instead of "String" instead of "String" in Scala

Why am I getting a [Some] object instead of a [String] object?
The Some object will not work as a string parameter in a method call.

config defreturns String, so I expect the type to be String.
But when I type "Hello" Scala, return it.

the code

    def config(s: String) = Play.current.configuration.getString(s).toString()
    Logger.info(config("recaptcha.publicKey"))
    Logger.info("Hello")

Output

[info] application - Some(6LeDMdASAAAAAC4CFIDY-5M7NEZ_WnO0NO9CSdtj)
[info] application - Hello
+3
source share
2 answers

You do not necessarily call toString()on Option[String](which returns Play.current.configuration.getString()), try the following:

def config(s: String) = Play.current.configuration.getString(s).get

or perhaps preferably:

Play.current.configuration.getString(s).getOrElse("some default")
+9
source

getString [String], , . - , Some (string), , get().

+7

All Articles