progs/lecture4.scala
changeset 319 ed7543c5d317
parent 278 57b5bba67467
child 320 90aed247c8cf
equal deleted inserted replaced
318:f1215a72cd88 319:ed7543c5d317
   432 // late extension problem; namely, given a class C and a class T, 
   432 // late extension problem; namely, given a class C and a class T, 
   433 // how to have C extend T without touching or recompiling C. 
   433 // how to have C extend T without touching or recompiling C. 
   434 // Conversions add a wrapper when a member of T is requested 
   434 // Conversions add a wrapper when a member of T is requested 
   435 // from an instance of C.
   435 // from an instance of C.
   436 
   436 
   437 //Another example
   437 //Another example (TimeUnit in 2.13?)
   438 
   438 
   439 case class Duration(time: Long, unit: TimeUnit) {
   439 case class Duration(time: Long, unit: TimeUnit) {
   440   def +(o: Duration) = Duration(time + unit.convert(o.time, o.unit), unit)
   440   def +(o: Duration) = Duration(time + unit.convert(o.time, o.unit), unit)
   441 }
   441 }
   442 
   442