3 ms·
C# also does this, and so do Python, JavaScript and Visual Basic. Java is the odd one out by not supporting properties.
by ptx 6y ago
C# also does this, and so do Python, JavaScript and Visual Basic. Java is the odd one out by not supporting properties.
- Too 6y agoSupporting properties is one thing, having assignments copy the backing property as a lazy evaluated function-pointer another, even if value is supposedly a int. Python getter properties are evaluated instantly on assignment. To convert them back into function-pointers like the Kotlin example above you really have to go out of your way by deep diving into inspect module. The result is a property-object which is not assignable to a int-variable, but type checking probably wouldn't go this deep as inspect naturally is very dynamic in its nature. My guess is Kotlin does this as a way of structural typing, if it walks like a int and talks like an int it is an int.
- usrusr 6y agoDo those others heavily advertise the difference between var and val as a core feature and then sabotage it by dressing up getters (that are evaluated on each call) as immutable values?