Add a variable to a class instance at runtime: Difference between revisions

Content added Content deleted
(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
Line 326: Line 326:
=={{header|Elena}}==
=={{header|Elena}}==
ELENA does not support adding a field at run-time but it can be simulated with the help of a mix-in.
ELENA does not support adding a field at run-time but it can be simulated with the help of a mix-in.
ELENA 3.x
ELENA 3.1
<lang elena>#import extensions.
<lang elena>import extensions.


class Extender :: BaseExtender
class Extender :: BaseExtender
{
{
object prop(foo) theField.
object foo :: prop(theField).
constructor new : anObject
constructor new : anObject
Line 346: Line 346:
anObject := Extender new:anObject.
anObject := Extender new:anObject.


anObject set &foo:"bar".
anObject foo := "bar".


console writeLine:anObject:".foo=":(anObject foo).
console printLine:anObject:".foo=":(anObject foo).


console readChar.
console readChar.