Created
June 14, 2011 22:09
-
-
Save kings13y/1026052 to your computer and use it in GitHub Desktop.
Example of type inference in Scala
This file contains 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
val a = 1 // this type gets inferred to be of type Int | |
val b = "b" // this type in inferred to be a String | |
val c = 2.0 // this type is inferred to be a Double | |
case class SomeThing | |
class SomeOtherThing | |
val d = SomeThing // this type is instantiated as SomeThing. Not no need for the 'new' keyword as this is a case class | |
val e = new SomeOtherThing // This type requires the new keyword as no factory method is created for non case classes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment