Inheritance using MooTools <font size=-2><a href=http://www.lifemichael.com/en/?page_id=73 target=_blank>PRO</a></font>
Define Constructor When Using MooTools <font size=-2><a href=http://www.lifemichael.com/en/?page_id=73 target=_blank>PRO</a></font>
Define Simple Class using MooTools <font size=-2><a href=http://www.lifemichael.com/en/?page_id=73 target=_blank>PRO</a></font>
MooTools Function Binding <font size=-2><a href=http://www.lifemichael.com/en/?page_id=73 target=_blank>PRO</a></font>
Generics Wild Card in Scala <font size=-2><a href=http://www.lifemichael.com/en/?page_id=73 target=_blank>PRO</a></font>
When defining a variable of a generic type we can use a wild card instead of specifying the exact secondary type the generic type uses. object HelloSample { def main(args:Array[String]):Unit = { val a:MyStack[SportCar] = new MyStack[SportCar]; val b:MyStack[_ <: Car] = a; } } class Car class SportCar extends Car class MyStack[T] The following […]
Generics Contravariance in Scala <font size=-2><a href=http://www.lifemichael.com/en/?page_id=73 target=_blank>PRO</a></font>
When using generics Scala doesn’t support covariance. The following code doesn’t compile. object HelloSample { def main(args:Array[String]):Unit = { val a:MyStack[SportCar] = new MyStack[SportCar]; val b:MyStack[Car] = a; } } class Car class SportCar extends Car class MyStack[T] The following video clip shows the compilation error we get while trying to compile this code and […]
Type Bounds in Scala <font size=-2><a href=http://www.lifemichael.com/en/?page_id=73 target=_blank>PRO</a></font>
When we define a function or a class and we choose to use generics we can set limits on the unknown type: S <: T – means that S is a sub type of T S >: T – means that S is a super type of T It is also possible to mix between […]
Functions and Anonymous Classes in Scala <font size=-2><a href=http://www.lifemichael.com/en/?page_id=73 target=_blank>PRO</a></font>
When calling a function we indirectly invoke the apply method on the object that represents the function. We can use the anonymous inner class syntax for defining a new anonymous inner class that extends the Function relevant trait in order to create a new function. The following code sample shows that. object HelloSample { def […]
Functions as Objects in Scala <font size=-2><a href=http://www.lifemichael.com/en/?page_id=73 target=_blank>PRO</a></font>
Function values are treated as objects. The function A=>B is an abbreviation for using a new object instantiated from a class that extends the scala.Function1[A,B] trait and overrides the apply function. There are currently Function1, Function2, Function3… etc… up to Function22, that takes 22 parameters. The following code sample shows that. object HelloSample { def main(args:Array[String]):Unit […]
Anonymous Inner Class in Scala <font size=-2><a href=http://www.lifemichael.com/en/?page_id=73 target=_blank>PRO</a></font>
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 […]