Created
October 4, 2014 19:16
-
-
Save relrod/208b58ce10ff30ba6164 to your computer and use it in GitHub Desktop.
Scala is hilarious
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ricky@t520 ~$ scala | |
| Welcome to Scala version 2.11.2 (OpenJDK 64-Bit Server VM, Java 1.8.0_20). | |
| Type in expressions to have them evaluated. | |
| Type :help for more information. | |
| scala> Array("foo","bar")(2) | |
| <console>:8: error: type mismatch; | |
| found : Int(2) | |
| required: scala.reflect.ClassTag[String] | |
| Array("foo","bar")(2) | |
| ^ | |
| scala> (Array("foo","bar"))(2) | |
| <console>:8: error: type mismatch; | |
| found : Int(2) | |
| required: scala.reflect.ClassTag[String] | |
| (Array("foo","bar"))(2) | |
| ^ | |
| scala> val x = Array("foo","bar") | |
| x: Array[String] = Array(foo, bar) | |
| scala> x(2) | |
| java.lang.ArrayIndexOutOfBoundsException: 2 | |
| ... 33 elided | |
| scala> x(1) | |
| res3: String = bar | |
| scala> x.lift(2) | |
| res4: Option[String] = None | |
| scala> x.lift(1) | |
| res5: Option[String] = Some(bar) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment