Re: generics and arrays and multi-class collections



On 30 sep, 06:29, SadRed <cardinal_r...@xxxxxxxxxxx> wrote:

Yes. And the SuppressWarnings annotation may be our only feeble
solace. Wisdome is "use Java generics only at its shallowest".
Anything deeper can become confusing and unworkable.

Aight, I find it to be the most complex part of the Java language,
well, the only complex part. I have been trying endlessly to fix some
generics code that wouldn't compile, until I read a tutorial and
discovered that what I wanted couldn't be done. I now understand most
of it, but I wouldn't be surprised if I get bitten by something unseen
again.

For example, what exactly are the properties of

HashMap<Class<? extends Number>, List<? extends Number>>

This was the only way to get different kinds of (Lists of) Numbers
into the Map, but when I get() a List, I can't add anything into it,
unless I cast it, which generates a warning. Well, now I have *some*
type safety.

.