@GoToLoop this is unsafe:
List<
PVector> myList = new
ArrayList();
(you're running flawed code!).
Well, let's try to defend myself!
I guess every1 knows the effects of a generics declaration for a reference variable:
- It makes sure that methods like add(), addAll(), put(), putAll(), append(), set(), etc. accepts only the same data-type as the declared generics for that ref. variable.
- And my favorite 1, no need to use cast operators every time we use get() and such!
Now, what's the only effect of generics usage on
Collection instantiation part?:
It merely makes sure that in the rarest case we decide to pre-initialize it w/
another
Collection of sorts, it is indeed the same type as the declared generics.
Now tell me how ->
List<PVector> myList = new ArrayList<PVector>();
can be any safer than ->
List<PVector> myList = new ArrayList(); ???
That
List is being instantiated empty!
Placing a <
PVector> to the right won't make any difference at all, but more verbosity!!!
Actually, initializing a
Collection w/ anything makes it incompatible w/ JS Mode!
Even such example as ->
List<Integer> integers = new ArrayList<Integer>(strings);
isn't that brilliant, b/c any1 can easily spot that variable
strings is a
List<
String>.
Although it's an extra safe-guard, it's very rare for some1 to make such "crass" bug!
Nevertheless, it's important for when the pre-filling
Collection comes from a source
we can't be much sure of its generics content.
Also be aware that any generics is stripped off once program is compiled!
Generics are only relevant for the Java compiler. There's none present in byte-code!