Created
February 28, 2018 18:50
-
-
Save Jasper-M/dc46ffc52bb968c7dbe10db61f3f130b to your computer and use it in GitHub Desktop.
Implicits that are only implicitly available
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
scala> object Module { | |
| type Foo[T] = Internal.Foo[T] | |
| object Foo { | |
| def pubMethod = "Hi!" | |
| } | |
| | |
| private[Module] object Internal { | |
| trait Foo[T] | |
| object Foo { | |
| implicit def FooString = new Foo[String] { | |
| override def toString = "it's me!" | |
| } | |
| } | |
| } | |
| } | |
defined object Module | |
scala> implicitly[Module.Foo[String]] | |
res0: Module.Foo[String] = it's me! | |
scala> Module.Foo.pubMethod | |
res1: String = Hi! | |
scala> Module.Internal.Foo.FooString | |
<console>:13: error: object Internal in object Module cannot be accessed in object Module | |
Module.Internal.Foo.FooString | |
^ |
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
scala> object Module { | |
| trait Foo[T] | |
| private[Module] object Foo { | |
| implicit def FooString = new Foo[String] { | |
| override def toString = "it's me!" | |
| } | |
| } | |
| } | |
defined object Module | |
scala> implicitly[Module.Foo[String]] | |
res0: Module.Foo[String] = it's me! | |
scala> Module.Foo.FooString | |
<console>:13: error: object Foo in object Module cannot be accessed in object Module | |
Module.Foo.FooString | |
^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment