Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #4550

Re: Java generics and type erasure

Newsgroups comp.lang.java.programmer
Subject Re: Java generics and type erasure
From Ian Shef <invalid@avoiding.spam>
References <9d4c2b16-beb5-40b1-87a2-f03e971efeed@k17g2000vbn.googlegroups.com> <nospam-871A48.22542123052011@news.aioe.org> <irfgkl$lca$1@news.albasani.net> <Xns9EEF8515AF3B6vaj4088ianshef@138.125.254.103> <irh6kb$gse$1@news.albasani.net>
Message-ID <Xns9EEFA3AE378DDvaj4088ianshef@138.125.254.103> (permalink)
Date 2011-05-24 23:05 +0000
Organization Raytheon Company

Show all headers | View raw


Lew <noone@lewscanon.com> wrote in news:irh6kb$gse$1@news.albasani.net:

<snip>
> OK, I see what you mean, but that's only after the compiler's
> enforcement of the type parameters.  If they don't fly, the erasure
> doesn't happen.  So what I meant, and said incorrectly, that *to the
> compiler*, the generic type exists, but *to the runtime* it's already
> been erased.  So the fact that the type parameter has been erased shows
> up at run time, and the type information in the parameter shows up at
> compile time. 

Sounds like we are in violent agreement.
> 
> You are correct.  The difference between how you and I think of it is
> that I'm thinking in terms of where you see the type-parameter errors,
> that is, on input to the compiler.  You're seeing where the actual
> erasure occurs, that is, on output from the compiler.

More violent agreement:  Type erasure takes place at compile time and 
becomes visible at run time.
> 
> I will be more rigorous in my explanation of that henceforth.  Thanks
> for the nuance.
> 

OK.  I didn't mean to get pedantic but my fingers ran away on their own.   
Be rigorous if you want to; some will get the nuance (I'm glad you did) and 
some won't.

By the way, the description of the particular situation examined here 
(where instance fields of a type are treated as raw because the type itself 
is used raw) seem to be covered by version 3 of the JLS in paragraph 4.8.  
I am not sure exactly which sentence in 4.8 covers this, but I am sure that 
it is there because the examples show similar situations.  Perhaps it is 
covered by this:

"The type of a constructor (§8.8), instance method (§8.8, §9.4), or non-
static field (§8.3) M of a raw type C that is not inherited from its 
superclasses or superinterfaces is the erasure of its type in the generic 
declaration corresponding to C."


Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Java generics and type erasure Marcin Pietraszek <m.pietraszek@gmail.com> - 2011-05-23 13:18 -0700
  Re: Java generics and type erasure "John B. Matthews" <nospam@nospam.invalid> - 2011-05-23 22:54 -0400
    Re: Java generics and type erasure Lew <noone@lewscanon.com> - 2011-05-24 01:45 -0400
      Re: Java generics and type erasure Marcin Pietraszek <m.pietraszek@gmail.com> - 2011-05-24 12:39 -0700
      Re: Java generics and type erasure Ian Shef <invalid@avoiding.spam> - 2011-05-24 20:04 +0000
        Re: Java generics and type erasure Lew <noone@lewscanon.com> - 2011-05-24 17:06 -0400
          Re: Java generics and type erasure Ian Shef <invalid@avoiding.spam> - 2011-05-24 23:05 +0000
            Re: Java generics and type erasure Susan Calvin <s.calvin@usr.invalid> - 2011-05-25 00:13 +0000
              Re: Java generics and type erasure Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-05-26 10:18 +1200
                Re: Java generics and type erasure Susan Calvin <s.calvin@usr.invalid> - 2011-05-26 01:12 +0000
                Re: Java generics and type erasure Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-05-26 13:59 +1200
                Re: Java generics and type erasure Susan Calvin <s.calvin@usr.invalid> - 2011-05-26 04:18 +0000
                Re: Java generics and type erasure Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-05-26 18:48 +1200
                Re: Java generics and type erasure Esmond Pitt <esmond.pitt@bigpond.com> - 2011-05-26 18:34 +1000
                Re: Java generics and type erasure Lew <noone@lewscanon.com> - 2011-05-26 07:45 -0400
                Re: Java generics and type erasure "John B. Matthews" <nospam@nospam.invalid> - 2011-05-26 15:25 -0400
                Re: Java generics and type erasure Esmond Pitt <esmond.pitt@bigpond.com> - 2011-05-27 12:01 +1000
                Re: Java generics and type erasure Lew <noone@lewscanon.com> - 2011-05-26 22:15 -0400
                Re: Java generics and type erasure Esmond Pitt <esmond.pitt@bigpond.com> - 2011-05-27 13:04 +1000
                Re: Java generics and type erasure Lew <noone@lewscanon.com> - 2011-05-27 01:27 -0400
                Re: Java generics and type erasure Esmond Pitt <esmond.pitt@bigpond.com> - 2011-05-27 18:07 +1000
                Re: Java generics and type erasure Lew <noone@lewscanon.com> - 2011-05-27 10:18 -0400
                Re: Java generics and type erasure Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-05-27 17:03 +0000
                Re: Java generics and type erasure Lew <noone@lewscanon.com> - 2011-05-27 13:27 -0400
                Re: Java generics and type erasure Esmond Pitt <esmond.pitt@bigpond.com> - 2011-05-30 15:19 +1000
                Re: Java generics and type erasure Tom McGlynn <taqmcg@gmail.com> - 2011-05-26 19:53 -0700
                Re: Java generics and type erasure Lew <noone@lewscanon.com> - 2011-05-27 01:30 -0400
                Re: Java generics and type erasure Esmond Pitt <esmond.pitt@bigpond.com> - 2011-05-27 18:09 +1000
                Re: Java generics and type erasure Lew <noone@lewscanon.com> - 2011-05-27 10:22 -0400
                Re: Java generics and type erasure Esmond Pitt <esmond.pitt@bigpond.com> - 2011-05-30 15:23 +1000
                Re: Java generics and type erasure Lew <noone@lewscanon.com> - 2011-05-30 02:35 -0400

csiph-web