Created
September 13, 2012 19:36
-
-
Save leedm777/3717022 to your computer and use it in GitHub Desktop.
Object can be functions in Scala
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
scala> object ImaFunction { | |
| def apply() { println("I am a function") } | |
| } | |
defined module ImaFunction | |
scala> case class Sois(name: String) { | |
| def apply() { printf("%s is also a function", name) } | |
| } | |
defined class Sois | |
scala> ImaFunction() | |
I am a function | |
scala> val x = Sois("x") | |
x: Sois = Sois(x) | |
scala> x() | |
x is also a function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment