Created
August 15, 2015 01:46
-
-
Save yuuichi-fujioka/67ec205ea6b2edd2f2af to your computer and use it in GitHub Desktop.
some examples
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
class Foo(message: String) { | |
def print_msg() = { | |
println(message) | |
} | |
} | |
object Foo { | |
def apply(message: String) = { | |
println("Foo.apply: " + message) | |
new Foo(message) | |
} | |
} | |
object Bar { | |
def apply(message: String) = { | |
println("Bar.apply: " + message) | |
new Foo(message) | |
} | |
} | |
object Ap extends App{ | |
val f1: Foo = new Foo("Messag001") | |
f1.print_msg() // Messge001 | |
val hoge: Foo = Foo { | |
"Hoge Hoge" | |
} // Foo.apply: Hoge Hoge | |
hoge.print_msg() // Hoge Hoge | |
def x() = Bar { | |
"Hello, Apply" | |
} | |
val v = x() | |
v.print_msg() | |
def y = Bar { | |
"Hello, Apply2" | |
} | |
y.print_msg() | |
y | |
val z = () => println("Hi! John") | |
z() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment