On Tuesday, 3 December 2019 at 16:03:18 UTC, Ola Fosheim Grøstad wrote:
But this doesn't work in D.

That's my point - it is unsound in the static type system and D correctly rejects it. Might work in a dynamic language, but not in static.

Yes, but when do you need to do it? So it is typesafe, but what would the use case be?

You could conceivably write a child class that wraps or converts. For example, perhaps:

class Serializer {
    void serialize(Serializable s) {}
}

class ExtendedSerializer: Serializer {
    override void serialize(Object o) {
        super.serialize(reflectToSerializable(o));
    }
}

I probably wouldn't do it that way... and I can't think of a time I actually used this myself which is why I had to make something up. But still, it conceivably makes sense.

I've got a feeling that one could do something interesting with such semantics that would make all this variance-stuff cleaner... somehow. But I haven't given it a lot of thought. Just a feeling. :)

Maybe, I haven't thought a lot of it.
            • Re: ... Robert M. Münch via Digitalmars-d-announce
              • ... Adam D. Ruppe via Digitalmars-d-announce
              • ... Ola Fosheim Grøstad via Digitalmars-d-announce
              • ... Adam D. Ruppe via Digitalmars-d-announce
              • ... Ola Fosheim Grøstad via Digitalmars-d-announce
              • ... Ola Fosheim Grøstad via Digitalmars-d-announce
              • ... Adam D. Ruppe via Digitalmars-d-announce
              • ... Adam D. Ruppe via Digitalmars-d-announce
              • ... Ola Fosheim Grøstad via Digitalmars-d-announce
              • ... Ola Fosheim Grøstad via Digitalmars-d-announce
              • ... Adam D. Ruppe via Digitalmars-d-announce
              • ... Ola Fosheim Grøstad via Digitalmars-d-announce
          • Re: inter... Ola Fosheim Grøstad via Digitalmars-d-announce
  • Re: interfaces and contrac... Meta via Digitalmars-d-announce

Reply via email to