Skip to content

Instantly share code, notes, and snippets.

@jsuereth
Created March 16, 2009 02:00
Show Gist options
  • Save jsuereth/79644 to your computer and use it in GitHub Desktop.
Save jsuereth/79644 to your computer and use it in GitHub Desktop.
Welcome to Scala version 2.8.0.r0-b20090301210344 (Java HotSpot(TM) Client VM, Java 1.6.0_10).
Type in expressions to have them evaluated.
Type :help for more information.
scala> trait ReponseHelper[A];
defined trait ReponseHelper ^
scala> def doSomething[A](x : ReponseHelper[_ <: A]) : A = null.asInstanceOf[A]
doSomething: [A](ReponseHelper[_ <: A])A ^
scala> val testHelper = new ReponseHelper[Int] {}
testHelper: java.lang.Object with ReponseHelper[Int] = $anon$1@170119f
scala> doSomething(testHelper)
<console>:8: error: type mismatch;
found : java.lang.Object with ReponseHelper[Int]
required: ReponseHelper[_ <: ?]
doSomething(testHelper)
^
scala> val testHelper2 : ReponseHelper[Int] = new ReponseHelper[Int] {}
testHelper2: ReponseHelper[Int] = $anon$1@1298826
scala> doSomething(testHelper2)
<console>:8: error: type mismatch;
found : ReponseHelper[Int]
required: ReponseHelper[_ <: ?]
doSomething(testHelper2)
^
scala> def doSomething(x : Int) = x
doSomething: (Int)Int
scala> doSomething(testHelper2)
<console>:8: error: type mismatch;
found : ReponseHelper[Int]
required: Int
doSomething(testHelper2)
^
scala> doSomething(testHelper)
<console>:8: error: type mismatch;
found : java.lang.Object with ReponseHelper[Int]
required: Int
doSomething(testHelper)
^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment