re: Explain Generics Like I'm Five VIEW POST


In strictly typed languages, Generics are a way to make an abstraction like a List or Map where the type isn't directly tied to the implementation. A Set for example, has standard operations that don't change whether you have a Set of cars or DOM Elements.

So you might set it up something like this.

class Set<E> {
public E get(int index) {
    return this._innerArray[index];
Set<Car> mySet = new Set<>();

That explains why I wouldn't be familiar with the concept from Ruby or Javascript, since those languages are dynamically typed to begin with. Thanks!

code of conduct - report abuse