Final function parameters

You can use the final modifier on a function parameter to prevent the value of the parameter from changing within the function.

For example, the following code is valid:

package example

class FinalTest {
  function SuffixTest(greeting : String) {
    greeting = greeting + "fly"
    print(greeting)
  }
}

You can test this method with the code:

var f = new example.FinalTest()
var s = "Butter"
f.SuffixTest( s )

This code prints:

Butterfly

If you add the final modifier to the parameter, the code generates a compile error because the function attempts to modify the value of a final parameter:

class FinalTest {
  function SuffixTest(final greeting : String) {
    greeting = greeting + "fly"
    print(greeting)
  }
}