I have to construct the Map in Scala so that I can collect all the data from call to Java code. Possible values are String
, Integer
, Double
and null
. Is there a way to represent this Map in Scala? I am trying to have Option as follow but not sure what its type should be.
def createScalaMapaFromJavaBean(): Map[String, Option[XXX]] = {
val someJavaBean = getMyBeanValues()
Map(
"key1" -> Option(someJavaBean.getAgeAsInteger()),
"key2" -> Option(someJavaBean.getSalaryAsDouble()),
"key3" -> Option(someJavaBean.getNameAsString()),
"key4" -> Option(someJavaBean.getSomeFieldValuesAsNull()
)
}