1. 16
  1.  

  2. 5

    I arrived at a similar conclusion a few years ago when I encountered differences between what the language specification and the compiler considered to be correct type-casting. Fortunately, generics in Java are essentially syntactic hints to the compiler and do not end up in the compiled bytecode (this both enables and prohibits some useful but possibly unintended features involving multiple inheritance over interfaces).

    1. 6

      Are you referring to type erasure? If so, could you expound on your thoughts a bit? I’ve always heard of type erasure in a negative context although recently have read a bit about it as if it’s a feature.

      1. 3

        Yes, type erasure. I suppose it depends on your perspective whether you view it as a feature or a hindrance. Generics were added to Java in version 5.0 (~2003 IIRC), and was an add-on to the compiler, not the runtime. This preserved forward-compatibility with non-Generic code using the same API (e.g. Java Collections). Furthermore, even with the oddities and limitations of the compiler with respect to Generics, it is usually possible to work around those issues via type erasure or (in the special case I linked above) multiple-casts.