Fahad/CodeSamples/Main.scala
changeset 44 a751aa1ee4f7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Fahad/CodeSamples/Main.scala	Sun Nov 09 19:25:10 2014 +0000
@@ -0,0 +1,45 @@
+package Main
+
+abstract class Buffer{
+  type T
+  val element: T
+}
+
+abstract class SeqBuffer extends Buffer{
+  type U
+  type T <: Seq[U]
+  def length = element.length
+}
+
+abstract class IntSeqBuffer extends SeqBuffer{
+  type U = Int
+}
+
+object AbstractTypeTest1 extends App{
+  def newIntSeqBuf(elem1: Int, elem2: Int): IntSeqBuffer =
+    new IntSeqBuffer{
+	  type T = List[U]
+	  val element = List(elem1, elem2)
+  }
+  val buf = newIntSeqBuf(7, 8)
+  println("length = " + buf.length)
+  println("content = " + buf.element)
+}
+
+abstract class Buffer2[+T] {
+  val element: T
+}
+
+abstract class SeqBuffer2[U, +T <: Seq[U]] extends Buffer2[T] {
+  def length = element.length
+}
+
+object AbstractTypeTest2 extends App {
+  def newIntSeqBuf(e1: Int, e2: Int): SeqBuffer2[Int, Seq[Int]] =
+    new SeqBuffer2[Int, List[Int]] {
+      val element = List(e1, e2)
+    }
+  val buf = newIntSeqBuf(7, 8)
+  println("length = " + buf.length)
+  println("content = " + buf.element)
+}