Created
December 12, 2021 05:02
-
-
Save bbarker/861b47e41e375da82cb396b7daf5264f to your computer and use it in GitHub Desktop.
let's try and be slightly more clever and use an element contained in the list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def exSetAllBeansToFirst(beanList: List[ScalaBean[?]]): Unit = | |
val firstBean = beanList.head // bad: don't use head if the list may be empty | |
beanList.foreach{bean => | |
bean.setTheA(firstBean.getTheA) | |
// ❌ Found: firstBean.A | |
// Required: bean.A | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment