Question: New to Scala, continue to struggle with `Option` related code. I have a HashMap built of Case Class instances that themselves contain hash maps with Case Class instance values. It is not clear to me how to access properties of the retrieved Class instances:

```
import collection.mutable.HashMap

case class InnerClass(name: String, age: Int)
case class OuterClass(name: String, nestedMap: HashMap[String, InnerClass])

// Load some data...hash maps are mutable
val innerMap = new HashMap[String, InnerClass]()
innerMap += ("aaa" -> InnerClass("xyz", 0))

val outerMap = new HashMap[String, OuterClass]()
outerMap += ("AAA" -> OuterClass("XYZ", innerMap))

// Try to retrieve data
val outerMapTest = outerMap.getOrElse("AAA", None)
val nestedMap = outerMapTest.nestedMap

```

This produces `error: value nestedMap is not a member of Option[ScalaFiddle.OuterClass]`

```
// Try to retrieve data a different way
val outerMapTest = outerMap.getOrElse("AAA", None)
val nestedMap = outerMapTest.nestedMap

```

This produces `error: value nestedMap is not a member of Product with Serializable`

Please advise on how I would go about getting access to `outerMapTest.nestedMap`. I'll eventually need to get values and properties out of the `nestedMap` HashMap as well.

Answer: 
A `HashMap` will return `None` if a `key` is not found so it is unnecessary to do `getOrElse` to return `None` if the key is not found.

A simple solution to your problem would be to use get only as below

Change your first `get` as

```
val outerMapTest = outerMap.get("AAA").get

```

you can check the output as 

```
println(outerMapTest.name)
println(outerMapTest.nestedMap)

```

And change the second `get` as 

```
val nestedMap = outerMapTest.nestedMap.get("aaa").get

```

You can test the outputs as 

```
println(nestedMap.name)
println(nestedMap.age)

```

Hope this is helpful
you can access the nestMap using below expression. 

```
scala> outerMap.get("AAA").map(_.nestedMap).getOrElse(HashMap())
res5: scala.collection.mutable.HashMap[String,InnerClass] = Map(aaa -> InnerClass(xyz,0))

```

if `"AAA"` didnt exist in the outerMap Map object then the below expression would have returned an empty HashMap as indicated in the `.getOrElse` method argument (`HashMap()`).