|
|
|
|
|
by kannanvijayan
244 days ago
|
|
> The same is true of a piece of code that writes through the reference or returns it. That's how sub-typing works. But it is not true that it is correctly typed with respect to a a supertype of A (it is not valid to call the code with a reference to a supertype of A). Code that only writes through the reference is correctly typed with respect to a super-type of A (it is valid to call the code with a reference to a supertype of A). > Have you ever programmed in a language with subtyping? Sigh, keep that snark for the twitter battles. I don't care enough about this to get snippy about it or to deal with folks who do. |
|
I'm not trying to be snarky, I genuinely want to know what you think of that code snippet I showed you. You claim it should work, but anyone with an understanding of programming would tell you it shouldn't. You can't write to a member variable that doesn't exist. Have you encountered inheritance before? Do you know what a “super-type” is? The mistake you're making here is very basic and I should like to know your level of experience.