Skip to content

Instantly share code, notes, and snippets.

@bbarker
Created December 12, 2021 04:57
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/12328e73399a490a19fe1f46a7eff8d8 to your computer and use it in GitHub Desktop.
Save bbarker/12328e73399a490a19fe1f46a7eff8d8 to your computer and use it in GitHub Desktop.
try to set values. Let's try making such a function
def polySetAllBeansTo[A](beanList: List[ScalaBean[A]], initBean: ScalaBean[A]): Unit =
beanList.foreach{bean =>
bean.setTheA(initBean.getTheA)
}
polySetAllBeansTo(beanList3, bean1)
// everything is now set to bean1's value
println(beanList2.map(_.getTheA))
polySetAllBeansTo(beanList2, bean1)
// ❌ Found: (Playground.beanList2 : List[Playground.ScalaBean[?]])
// Required: List[Playground.ScalaBean[Int]]
println(beanList2.map(_.getTheA))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment