
Type Erasure Magic in Swift - ulhas_sm
https://realm.io/news/altconf-hector-matos-type-erasure-magic/
======
scott_s
> In Java it is used to let the compiler know and it will erase the <T> and
> make it a concrete type.

It's the opposite. In Java, when you instantiate a generic class with a
concrete type, it will _erase_ that type in the generic class. So, the actual
code for Foo<String> and Foo<Integer> is the same; String and Integer are
erased, and inside of Foo, it just uses Object. For that reason, Foo<T> is not
allowed to do anything with T that would require knowing the actual type of T;
that knowledge has been erased. See
[https://docs.oracle.com/javase/tutorial/java/generics/erasur...](https://docs.oracle.com/javase/tutorial/java/generics/erasure.html)

With this confusion, it's hard for me to orient myself with how this applies
to Swift.

------
danra
As a TL;DR, or even as a starting point for diving deeper into the finer
points in the talk, it would be really helpful to attach the complete code
which demonstrates type erasure.

~~~
ulhas_sm
Agreed. Although, the code is in the presentation.

~~~
mcherm
It might be in the video (I don't have time to watch it to find out). It isn't
in the slides (which I can skim quickly, and therefore I did).

------
catnaroek
This seems like an apology for the unforgivable: type erasure is a language
_implementation detail_ , and thus it shouldn't affect language users. A user
might want to choose an implementation that uses monomorphization for
performance reasons, or an implementation that doesn't erase types for
debuggability reasons. But the language implementor's choice to use type
erasure shouldn't affect the meaning of code written by language users.

------
bpicolo
Why do all sorts of blogs have "Click to Read More" buttons these days? Seems
totally unnecessary.

~~~
Someone
It makes the adverts stand out more, and that pays the bills.

Edit: it seems the old location for adverts, the sidebar, is dead because
people zoom in on mobile and many users are on mobile.

Pop-ups also are somewhat dead because people have learned to close the not-
too obnoxious ones without paying attention.

