This file contains 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 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 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 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 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 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 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 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] |
This file contains 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 someStuffAny: List[SomeClass[Any]] = List(SomeClass("foo"), SomeClass(1)) |
This file contains 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 Inner[+A](a: A) | |
// Or: | |
case class Outer[+A](a: Inner[A]) |