Open wentinggy opened 3 years ago
Hello basically in that slide he showed an example of defining an immutable list using int array. To define an immutable list for other primitives/objects he meant that we can copy everything in the class and just change all the int to whatever primitives we want, for e.g. double[] array
You could potentially create different ImLists for double, boolean etc. but the point of this question in the slide is to make you realise that doing so would be violating the abstraction principle (there are commonalities between all these lists - they have the 'structure' of an ImList after all). These ImLists of different primitives/objects can have common methods, so we're trying to create a generic ImList that can apply to all types instead.
For example, if the initial immutable list is written for integer type, you can only use the codes for integer and if you would like to use it for other types such as string, double, boolean, object etc., it's something like using that initial code that you wrote but changing the type to what you would like
E.g. instead of List
Hi as what many others have mentioned the prof used int[] array as an example. You can change all the int to double for instance but that would result in unnecessary duplication of code so it is best to use generics by using
thankyou everyone!
Description
During lecture 7, prof explained that to define an immutable list for other primitives/objects we can copy the entire class, change int to double. But I'm still unsure of how that works. Does anyone have any idea how the code should look like/ what does changing int to double exactly mean? (slide 3/16) Thankyou!
Screenshots