Skip to content

Instantly share code, notes, and snippets.

@bbarker
Created December 12, 2021 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbarker/861b47e41e375da82cb396b7daf5264f to your computer and use it in GitHub Desktop.
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
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