Skip to content

Instantly share code, notes, and snippets.

@mariuszklinger
Created March 26, 2014 15:21
Show Gist options
  • Save mariuszklinger/9785861 to your computer and use it in GitHub Desktop.
Save mariuszklinger/9785861 to your computer and use it in GitHub Desktop.

Revisions

  1. mariuszklinger created this gist Mar 26, 2014.
    34 changes: 34 additions & 0 deletions scala generics
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    import scala.collection.mutable.PriorityQueue
    import scala.math.Ordering._
    import scala.util.Sorting
    import Implicits._

    class MyType{

    }

    object Implicits {
    //implicit objects can't be top-level ones
    implicit object MyTypeQueOrdering extends Ordering[MyType] {
    def compare(n1: MyType, n2: MyType) = -1
    }
    }

    class MyTypeQue extends PriorityQueue[MyType]{

    }

    object Main {

    def main(args: Array[String]) = {
    val q = new MyTypeQue

    q += new MyType
    q += new MyType
    q += new MyType

    println(q.length)

    }

    }