Something like ADL from C++?
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Fri Dec 6 01:18:03 UTC 2024
On 06/12/2024 1:47 PM, Alexandru Ermicioi wrote:
> On Thursday, 5 December 2024 at 21:58:14 UTC, Richard (Rikki) Andrew
> Cattermole wrote:
>> If you are forcing users of a parent class to add the call explicitly
>> into the parent, its a major pain that other languages simply do not
>> have. Not to mention easily forgotten.
>>
>> This is what my attribute that I said I'm thinking about
>> ``@reinterptAsChild`` would solve.
>
> I'm confused for example. What is the problem you're mentioning here?
>
> If it is inheritance, then you either predefine the inheritance
> structure through annotations just like Jakson lib in java https://
> www.javadoc.io/doc/com.fasterxml.jackson.core/jackson-annotations/
> latest/com/fasterxml/jackson/annotation/JsonTypeInfo.html, or use
> runtime reflection to check what child it is and use respective
> serializer for it that is prerecorded.
We do not have runtime reflection. We cannot copy languages that do,
including for your example that isn't an alternative to runtime reflection.
```d
interface ISerialize {
void serialize();
}
class SerializableRoot {
void serialize() {
// serialize here
}
}
class MyType : SerializableRoot {
@thing int field;
...
}
```
Some how SerializableRoot.serialize has to be able to see the child
MyType class. We have no good way of handling that currently.
The attribute allows the serialize method to think that its in MyType
instead.
More information about the Digitalmars-d
mailing list