abstract class Dickmacher case class Beverage(name: String, cal: Int) extends Dickmacher case class Food(name: String, cal: Int) extends Dickmacher case class Meal(name: String, food: Food, drink: Beverage) extends Dickmacher case class Combo(starter: Dickmacher, main: Dickmacher) extends Dickmacher val coke = Beverage("Cola", 50) val burger = Food("Big Mac", 400) println(coke + " and " + burger) val wormup = Meal("Happy Meal", burger, coke) val primetime = Combo(wormup, new Combo(Food("Muffin", 200), Beverage("Coffee", 30))) //deep toString println(wormup) println(primetime) //deep equals println(wormup.drink == Beverage("Cola", 50)) //true println(wormup.drink == primetime.main) //false val fatCombo = new Combo(Food("Muffin", 200), Beverage("Coffee", 30)) val ohneZuckerCombo = new Combo(Food("Muffin", 200), Beverage("Coffee", 5)) println(fatCombo == ohneZuckerCombo) //false println(ohneZuckerCombo == new Combo(Food("Muffin", 200), Beverage("Coffee", 5))) //true
Friday, September 28, 2012
Case Classes
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment