progs/lecture4.scala
changeset 319 b84ea52bfd8f
parent 278 0c2481cd8b1c
child 320 cdfb2ce30a3d
equal deleted inserted replaced
318:029e2862bb4e 319:b84ea52bfd8f
   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