Created
August 1, 2013 20:33
-
-
Save Lakret/6135015 to your computer and use it in GitHub Desktop.
Check, whether implicit conversion exists.
(Source of idea: http://stackoverflow.com/questions/5717868/test-if-implicit-conversion-is-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> def implicitExists[A](implicit i: A = null) = i != null | |
implicitExists: [A](implicit i: A)Boolean | |
scala> trait Constructable[+A] { def get: A } | |
defined trait Constructable | |
scala> case class Page() | |
defined class Page | |
scala> implicitExists[Constructable[Page]] | |
res0: Boolean = false | |
scala> implicit val pageToConstr = new Constructable[Page] { def get = Page() } | |
pageToConstr: Constructable[Page] = $anon$1@2e7e34db | |
scala> implicitExists[Constructable[Page]] | |
res1: Boolean = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment