Fixed
Pinned fields
Click on the next to a field label to start pinning.
Details
Details
Details
Sentry
Sentry
Sentry
Created August 20, 2024 at 3:55 AM
Updated August 20, 2024 at 4:00 AM
Resolved August 20, 2024 at 3:56 AM
BoxLang: Our new JVM Dynamic Language made by Ortus! Check it out: https://www.boxlang.io
Add
final
assignment modifier for assignmentsfinal foo = "bar"
this, of course, can be used with other modifiers
final static foo = "bar" final var foo = "baz"
The only 2 modifiers that can’t be used together are
var
andstatic
since they represent different scopes.When a variable is declared as
final
, the scope it is being set into will track a list of keys which are designated as final, and will prevent those keys from being modified in the future.This is ONLY a feature of scopes. Structs and other struct-like container will not have a final concept.
Note, using the
final
modifier on a UDFfinal function foo() {}
is basically the same as
final foo = ()->{}
since both register the
foo
variable as “final” in thevariables
scope.The following operations check the final keys
declaring a UDF
setting a variable
calling
scope.put()
,scope.assign()
,scope.remove()
or any BIF that delegates to these such asscope.delete()
orstructDelete( scope, "foo" )
Notes:
unlike
const
these are not compiler constants and provide no bytecode-level optimization. This is due to the fact nearly all symbol resolution happens at runtimeunlike Java`s
final
, there is no bytecode level optimization for the same reasonThe only real purpose of
final
is to ensure the variable reference cannot be reassignedA
final
var reference cannot be re-assigned, HOWEVER, complex values like structs or arrays can still be mutated unless they are immutable.The following example
final lockDown = [ 1, 2, 3 ].toImmutable()
cannot be mutated OR re-assigned.
You can see the Set of final keys for a scope via the meta object
variables.$bx.meta.finalKeySet
You can also remove keys from the set to make a variable no longer final.
final foo = "bar" variables.$bx.meta.finalKeySet.clear() // Nothing is final in this scope now foo = "baz" // no error