Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Subtyping, where if a type B implements the public interface of type A, values of type B can be passed as A.

I am confused by this statement or it is going against what I understand.

If you have created a Type B variable, and you also have a new interface called A, and B implements A, then why would Type B variable's values be passed to A's values. 'A' is only an interface.



It says "values of type B", as in "instance of type B", can be passed as if they are "instance of type A" (which they are actually).

But yes, values inside B specific to type B will not be able to be accessed when manipulating the type A.


Thank you. :)


Passed 'as' A, not passed 'to' A.


That clears it up!




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: