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
val twentySomethings = for (user <- userBase if user.age >=20 && user.age < 30) yield user.name // i.e. add this to a list | |
twentySomethings.foreach(println) |
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
trait Greeter { | |
def meet(name: String): Unit | |
def greet(name: String): Unit = println("Hello, " + name + "!") | |
} |
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
object IdFactory { | |
private var counter = 0 | |
def create(): Int = { | |
counter += 1 | |
counter | |
} | |
} | |
val newId: Int = IdFactory.create()// YOU ACCESS OBJECTS BY ITS NAME |