Search:

Type: Posts; User: fortioni

Search: Search took 0.30 seconds.

  1. Re: Generics & 'Type Erasure': disingenuous documentation?

    But as I said, that example is bollocks code.
    If I saw that in some real code I would take it out back and have it shot.

    How should the compiler know that the above is not a valid cast?
    And what...
  2. Re: Generics & 'Type Erasure': disingenuous documentation?

    Show us an example then...as code.

    I presume you have encountered something that does cause a problem in real life, and not merely as a mental exercise, that you could use here to illustrate your...
  3. Re: Generics & 'Type Erasure': disingenuous documentation?

    Why should the cast to Object[] be flagged though?
    Will you flag casts to List<SomeClass>[] as well?
    How about any cast?
    Because that is essentially what you are suggesting...casting is always...
  4. Re: Generics & 'Type Erasure': disingenuous documentation?

    We're obviously talking at cross-purposes.

    The array assignment marked as Valid in the code snippet from the docs has always been valid, and is valid for things that do not involve generics....
  5. Re: Generics & 'Type Erasure': disingenuous documentation?

    Which has nothing to do with type erasure, since that is something specific to generics, and:
    Java Code:

    Object[] objects = new SomeClass[]();


    predates them by several years.

    You are...
  6. Re: Generics & 'Type Erasure': disingenuous documentation?

    But that would not fix the issue of casting SomeClass[] to an Object[], which has nothing at all to do with type erasure.
    Which is the point I was replying to.

    The above that you complained about...
  7. Re: Generics & 'Type Erasure': disingenuous documentation?

    No it shouldn't.
    Casting an array of something to an Object[] is not something that needs checking since everything is rooted in the Object class.

    It's possibly a side effect of the nature of...
  8. Re: Generics & 'Type Erasure': disingenuous documentation?

    The line labelled valid will never give an unchecked warning, even if the parameter were a List<String>[].
    Java Code:
    private static void test(List<String>[] l) {
    Object[] o = l; // This...
  9. Re: Generics & 'Type Erasure': disingenuous documentation?

    I don't know if it's the only solution, but it is the reasoning that the documentations give:

    "Type erasure enables Java applications that use generics to maintain binary compatibility with Java...
  10. Re: Generics & 'Type Erasure': disingenuous documentation?

    I gave it some more thoughts, but, suppose the requirements were:

    a) old code should keep on compiling and
    b) old code should keep on running and
    c) generics are supposed to be a compile time...
  11. Re: Generics & 'Type Erasure': disingenuous documentation?

    Ok, I reword that phrase: generics are a compile time issue in Java and hence its weakness. OTOH, when you want to go all the way, you end up with possible 'code bloat' as in C++'s templates; I guess...
  12. Re: Generics & 'Type Erasure': disingenuous documentation?

    I'm not sure what your issue is. It doesn't surprise me that Java doesn't complain about the add since the List variable, l, is not generic (and the compiler even warns you of this problem). If you...
  13. Re: Generics & 'Type Erasure': disingenuous documentation?

    Yep, the generated code is the same as before generics saw the light. Those casts are still needed during runtime because of the 'backward compatibility'. I don't understand your remark on 'heap...
  14. Re: Generics & 'Type Erasure': disingenuous documentation?

    No we can't because the compiler doesn't generate any new code at all; Generics is a compile time thingy; even the runtime casts are still present, even if the compiler 'knows' that a generic type is...
Results 1 to 14 of 14