You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The proposal in #1452 introduces the notion of boxing for an explicit extension type. A boxed entity obtained from an object whose static type is an extension type is an actual wrapper object where all the extension methods are available as regular instance members. This means that member invocation is subject to object-oriented dispatch (and even dynamic invocations are possible).
classZeroing {
Objectget zeroed =>"Zero!";
}
extension typeEonintimplementsZeroing {
Objectget zeroed =>0;
}
voidmain() {
E e =1;
Zeroed z = e.box; // OK.
z.zeroed; // `0`.
(z asdynamic).zeroed; // `0`.
}
The purpose of boxing is that it enables a choice: We may wish to use an extension type E to work on a large number of objects using a specific interface, without paying for the abstraction in terms of allocating and initializing wrapper objects. However, if a few of the objects must be used in some other context where the static type cannot be E then we'd need a wrapper object. This is safe and easy when boxing is a built-in mechanism.
The text was updated successfully, but these errors were encountered:
The proposal in #1452 introduces the notion of boxing for an explicit extension type. A boxed entity obtained from an object whose static type is an extension type is an actual wrapper object where all the extension methods are available as regular instance members. This means that member invocation is subject to object-oriented dispatch (and even dynamic invocations are possible).
The purpose of boxing is that it enables a choice: We may wish to use an extension type
E
to work on a large number of objects using a specific interface, without paying for the abstraction in terms of allocating and initializing wrapper objects. However, if a few of the objects must be used in some other context where the static type cannot beE
then we'd need a wrapper object. This is safe and easy when boxing is a built-in mechanism.The text was updated successfully, but these errors were encountered: