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 exSetAllBeansTo(beanList: List[ScalaBean[?]], initBean: ScalaBean[?]): Unit = | |
| beanList.foreach{bean => | |
| bean.setTheA(initBean.getTheA) | |
| // ❌ Found: initBean.A | |
| // Required: bean.A | |
| } |
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 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) |
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
| List(1, 2) | |
| List(2, 3) |
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
| println(beanList3.map(_.getTheA)) | |
| beanList3.foreach{bean => | |
| bean.setTheA(bean.getTheA+1) | |
| } | |
| println(beanList3.map(_.getTheA)) |
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
| val anyBean: ScalaBean[Any] = bean1 |
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
| case class ScalaBean[A](initA: A): | |
| private var theA: A = initA | |
| def getTheA: A = theA | |
| def setTheA(a: A): Unit = { | |
| this.theA = a | |
| } | |
| val bean1: ScalaBean[Int] = ScalaBean(1) | |
| val bean2: ScalaBean[String] = ScalaBean("Foo") | |
| val bean3: ScalaBean[Int] = ScalaBean(2) |
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
| val outsFromInsEx: List[Outer[?]] = List(in1, in2).map(Outer.apply) |
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
| val in1any2: Inner[Any] = (Inner("foo"): Inner[String]) | |
| // ❌ Found: Playground.Inner[String] | |
| // Required: Playground.Inner[Any] |
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
| val in1any: Inner[Any] = Inner("foo") | |
| val in2any: Inner[Any] = Inner(3) | |
| val outsFromInsAny2: List[Outer[Any]] = List(in1any, in2any).map(Outer.apply) |
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
| val someStuffAny2: List[SomeClass[Any]] = | |
| List(SomeClass("foo"): SomeClass[String], SomeClass(1): SomeClass[Int]) | |
| // ❌ Found: Playground.SomeClass[Int] | |
| // Required: Playground.SomeClass[Any] | |
| // ❌ Found: Playground.SomeClass[String] | |
| // Required: Playground.SomeClass[Any] |