Skip to content

Instantly share code, notes, and snippets.

@Renkai
Last active November 14, 2016 12:35
Show Gist options
  • Save Renkai/ddd59337d3c302eb3d061ff8d249413c to your computer and use it in GitHub Desktop.
Save Renkai/ddd59337d3c302eb3d061ff8d249413c to your computer and use it in GitHub Desktop.
/**
* Created by renkai on 16/9/7.
*/
object Main2 {
def isSingleton[A](a: A)(implicit ev: A <:< Singleton = null) = {
Option(ev).isDefined
}
def isSingleton2[A](a: A) = {
isSingleton(a)
}
def isSingleton3[A](a: A)(implicit ev: A <:< Singleton = null) = {
isSingleton(a)
}
def main(args: Array[String]): Unit = {
println("isSingleton(Main2) = " + isSingleton(Main2))
println("isSingleton2(Main2) = " + isSingleton2(Main2))
println("isSingleton3(Main2) = " + isSingleton3(Main2))
// isSingleton(Main2) = true
// isSingleton2(Main2) = false
// isSingleton3(Main2) = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment