Skip to content

Instantly share code, notes, and snippets.

@yuuichi-fujioka
Created August 15, 2015 01:46
Show Gist options
  • Save yuuichi-fujioka/67ec205ea6b2edd2f2af to your computer and use it in GitHub Desktop.
Save yuuichi-fujioka/67ec205ea6b2edd2f2af to your computer and use it in GitHub Desktop.
some examples
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