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
| package Hokuspokus | |
| object ImplicitMagic extends App { | |
| // implicit lambda which takes an int and returns a string | |
| implicit val i: Int = { | |
| implicit val i = null | |
| implicitly[Int] |
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
| package Hokuspokus | |
| object ImplicitMagic extends App { | |
| // implicit lambda which takes an int and returns a string | |
| implicit val f: Int => String = { | |
| // redfines the value f and sets the value implicitly to null | |
| implicit val f = null; |
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
| // defines the type class Showable as parametrically polymorphic type where T is the type variable | |
| trait Showable[T] { | |
| def show(t: T): String | |
| } | |
| // implementations of the type class | |
| object Showable { | |
| // implicitly returns a showable applied to the type Int which prints the int as string | |
| implicit def IntShow: Showable[Int] = new Showable[Int] { |
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
| package Hokuspokus | |
| object ImplicitMagic extends App { | |
| case class A(a: String, b: String, c: String) | |
| case class B(d: String, e: String, f: String, x: String) | |
| implicit def AtoB: A => B = a => B(a.a, a.b, a.c, a.x) | |
| def print(b: B): Unit = { |
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
| package Hokuspokus | |
| object ImplicitMagic extends App { | |
| case class A(a: String, b: String, c: String) | |
| case class B(d: String, e: String, f: String, x: String) | |
| implicit def AtoB: A => B = a => B(a.a, a.b, a.c, a.foobar) | |
| def print(b: B): Unit = { |
NewerOlder