Skip to content

Instantly share code, notes, and snippets.

@kings13y
Created June 14, 2011 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kings13y/1026052 to your computer and use it in GitHub Desktop.
Save kings13y/1026052 to your computer and use it in GitHub Desktop.
Example of type inference in Scala
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