diff options
Diffstat (limited to 'test/files/run/absoverride.scala')
-rw-r--r-- | test/files/run/absoverride.scala | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/test/files/run/absoverride.scala b/test/files/run/absoverride.scala index cf14ff475b..a3c03df0d7 100644 --- a/test/files/run/absoverride.scala +++ b/test/files/run/absoverride.scala @@ -1,35 +1,39 @@ abstract class AbsIterator { type T - def hasNext: boolean + def hasNext: Boolean def next: T } + trait RichIterator extends AbsIterator { - def foreach(f: T => unit): unit = + def foreach(f: T => Unit) { while (hasNext) f(next) + } } + class StringIterator(s: String) extends AbsIterator { - type T = char + type T = Char private var i = 0 def hasNext = i < s.length() - def next = { val x = s.charAt(i); i = i + 1; Console.println("next: " + x); x } + def next = { val x = s.charAt(i); i += 1; println("next: " + x); x } } + trait SyncIterator extends AbsIterator { - abstract override def hasNext: boolean = + abstract override def hasNext: Boolean = synchronized(super.hasNext) abstract override def next: T = synchronized { - Console.println("<sync>"); val x = super.next; Console.println("</sync>"); x + println("<sync>"); val x = super.next; println("</sync>"); x } } trait LoggedIterator extends AbsIterator { abstract override def next: T = { - val x = super.next; Console.println("log: " + x); x + val x = super.next; println("log: " + x); x } } class Iter2(s: String) extends StringIterator(s) with SyncIterator with LoggedIterator; object Test { - def main(args: Array[String]): unit = { + def main(args: Array[String]) { class Iter extends StringIterator(args(0)) with RichIterator with SyncIterator with LoggedIterator val iter = new Iter iter foreach Console.println |