release 2.9.2 • static typing • has object-oriented and functional language features • runs on the JVM (or CLR for .NET) • released under a BSD licence Thursday, 19 July 12
def walk } // but can also do stuff! trait Alive { def walk = println("pad pad") } class Dog extends Animal with Alive { ... } // or apply traits on the fly val kitty = new Cat with Alive Thursday, 19 July 12
package com.zestia // import a single class import java.util.List // import everything in java.util import java.util._ // alias an import import java.util.{ArrayList => JavaList} // import statics from Math import java.lang.Math._ Thursday, 19 July 12
// requires an object that has method “getById(id:Int)” // which returns an object with public var called “name” def showName(dao:{ def getById(id:Int):{var name:String} }, id:Int) { var record = dao.getById(id) println(record.name) } Thursday, 19 July 12
boom() } catch { case ioe: IOException => log.info("IOException; PANIC",ioe) // any other exception will get through as if we didn't try/catch } finally { // tidy up resources, always run even if there is an exception } } } Thursday, 19 July 12
= """(\d\d)/(\d\d)/(\d\d\d\d)""".r date match { case Date(day, "01", year) => "Jan " + day case Date(day, "02", year) => "Feb " + day case _ => "a date" } res1: java.lang.String = Feb 11 val Date(day, month, year) = date // outputs 3 vals day: String = 11 month: String = 02 year: String = 2010 Thursday, 19 July 12
(true) { receive { case s: String => { Thread.sleep(1000) println("To be or not to " + s) } case _ => println("?") } } } } AnActor.start AnActor ! "be" AnActor ! "be" AnActor ! "be. That is the questions" To be or not to be To be or not to be To be or not to be. That is the question Thursday, 19 July 12