Note: information on this page refers to Ceylon 1.0, not to the current release.

Type inference

Local declarations can often let the compiler infer the type.


value i = 1;      // infers Integer i
value b = true;   // infers Boolean
value tuple = ["", 1] // infers [String, Integer]
function f() => 1 // infers Integer()


You use the function keyword to infer a function's type, and value to infer a value's type.

Because Ceylon's type system is based on principal types there is only one type the compiler can infer.


Type inference cannot be used in all circumstances. It cannot be used:

  • on shared or formal declarations
  • when the value is specified after it's declared
  • to declare a parameter