Constructor Function: Scala · Ted Neward's Blog [PDF]

May 17, 2016 - Object method constructor. Scala allows us to create per-class methods on the class object, providing a c

3 downloads 19 Views 927KB Size

Recommend Stories


Manualul inginerului constructor pdf
Courage doesn't always roar. Sometimes courage is the quiet voice at the end of the day saying, "I will

TED ESKİŞEHİR KOLEJİ PDR BLOG SAYFASI
Your task is not to seek for love, but merely to seek and find all the barriers within yourself that

PdF Scala Cookbook
And you? When will you begin that long journey into yourself? Rumi

[PDF] Download Blog, Inc
Silence is the language of God, all else is poor translation. Rumi

@BamarSpeedShop | Karismahideung's Blog [PDF]
Tail tidy adalah spakbor belakang pendek, dimana fungsinya untuk menempatkan plat nomer dan lampu sein. Penggunaannya bisa menambah kesan racy, simple dan clean pada motor beraliran sport seperti Yamaha R15. Produk ini dibuat khusus untuk Yamaha R15

Penulis Blog | www.edipsw.com [PDF]
Penulis Blog | www.edipsw.comwww.edipsw.com/penulis-blog/ - Translate this page

Blog Platform PDF
Goodbyes are only for those who love with their eyes. Because for those who love with heart and soul

[PDF] Blog, Inc
If your life's work can be accomplished in your lifetime, you're not thinking big enough. Wes Jacks

Blog - The Mesh [PDF]
Oct 18, 2014 - Jika anda membutuhkan jasa bersih rumah atau yang biasa disebut sebagai cleaning service di bandung anda bisa menghubungi kami. Kami akan ...... Meja kursi pada umumnya dibuat menggunakan bahan kayu jati, mahoni, meh dan trembesi. Memb

Scala Sockelleisten Scala Skirts
You often feel tired, not because you've done too much, but because you've done too little of what sparks

Idea Transcript


trait Interface { def operation(adjust: Int) : Int; } object Implementation { def construct(startingValue : Int) : Interface = { class Impl(var current : Int) extends Interface { def operation(adjust: Int) : Int = { current += adjust return current } } return new Impl(startingValue) } } object App { def main(args : Array[String]) = { val intf = Implementation.construct(100) System.out.println(intf.operation(10)) } }

trait Interface { def operation(adjust: Int) : Int; } object Interface { def apply(startingValue : Int) : Interface = { class Impl(var current : Int) extends Interface { def operation(adjust: Int) : Int = { current += adjust return current } } return new Impl(startingValue) } } object App { def main(args : Array[String]) = { val intf = Interface(100) System.out.println(intf.operation(10)) } }

trait Interface { def operation(adjust: Int) : Int; } object Interface { var constructorFn = construct _ def apply(startingValue: Int) : Interface = constructorFn(startingValue) def construct(startingValue : Int) : Interface = { class Impl(var current : Int) extends Interface { def operation(adjust: Int) : Int = { current += adjust return current } } return new Impl(startingValue) } } object App { def main(args : Array[String]) = { val intf = Interface(100) System.out.println(intf.operation(10)) Interface.constructorFn = { startingValue => class Impl(var current : Int) extends Interface { def operation(adjust: Int) : Int = { current += adjust * 2 return current } } new Impl(startingValue) } val intf2 = Interface(100) System.out.println(intf2.operation(10)) } }

Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_20). Type in expressions for evaluation. Or try :help. scala> val capitals = Map("Tacoma" -> "WA") capitals: scala.collection.immutable.Map[String,String] = Map(Tacoma -> WA) scala> val pops = Map("Seattle" -> 5000000) pops: scala.collection.immutable.Map[String,Int] = Map(Seattle -> 5000000)

← Õ

Smile Life

When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile

Get in touch

© Copyright 2015 - 2024 PDFFOX.COM - All rights reserved.