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 […]

The Nothing Type in Scala PRO

The main usage for Nothing is when specifying the return type for methods which never return normally (e.g. throw an exception when been called). object Sample { def main(args:Array[String]):Unit = { val ob = getMyStack[Int](10) } def getMyStack[T](num:Int) = { new EmptyMyStack[T] } } abstract class MyStack[T](size:Int) { def data:T; } class EmptyMyStack[T] extends MyStack[T](0) […]

Generic Functions in Scala PRO

The Scala programming language allows us to define generic functions. This code sample shows that. object Sample { def main(args:Array[String]):Unit = { val ob = getMyStack[Int](10) } def getMyStack[T](num:Int) = { new MyStack[T](num) } } class MyStack[T](size:Int) { //… } The following video clips overviews this code sample, shows its execution and provides more information.

Skip to content Update cookies preferences