Anonymous Inner Class in Scala PRO

Scala allows us to define anonymous inner classes. The syntax is very similar to the one we know in Java.

object Demo
{
  def main(args:Array[String]):Unit =
  {
    val ob = new MyStack[Int](0)
    {
      def data:Nothing = throw new Exception("empty stack");
    }
  }
}

abstract class MyStack[T](size:Int)
{
  def data:T;
}

The following video clip overviews this code sample.

Share:

The Visitor Design Pattern

The Visitor Design Pattern

The visitor design pattern allows us to add operations to objects that already exist without modifying their classes and without extending them.

The Beauty of Code

Coding is Art! Developing Code That Works is Simple. Develop Code with Style is a Challenge!

Update cookies preferences