Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: "John B. Matthews" Newsgroups: comp.lang.java.programmer Subject: Re: Java generics and type erasure Date: Thu, 26 May 2011 15:25:57 -0400 Organization: The Wasteland Lines: 39 Message-ID: References: <9d4c2b16-beb5-40b1-87a2-f03e971efeed@k17g2000vbn.googlegroups.com> <4dde10b0$0$67777$c30e37c6@exi-reader.telstra.net> NNTP-Posting-Host: LQJtZWzu+iKlBROuDg+IUg.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:4608 In article , Lew wrote: > On 05/26/2011 04:34 AM, Esmond Pitt wrote: > > On 26/05/2011 4:48 PM, Lawrence D'Oliveiro wrote: > >>> No -- presumably, it would have caused problems compiling 1.4 source code > >>> against 1.5's libraries, not running existing 1.4 bytecode linked to 1.5 > >>> libraries. > >> > >> In Java terms, what’s the difference? > > > > The difference is that generic type-signatures are present in > > .class files for compilation purposes even though generics are > > erased to their lower bounds at runtime, so that the compiler can > > enforce the semantics of generics. > > This contradicts the statement that Ian Shef made upthread that type > erasure occurs in compilation. I don't see a contradiction. Since 1.5, the compiler puts Type and GenericDeclaration information in the class file for access via reflection, as shown using javap; but the information is not otherwise used at runtime. > It seems I was correct after all, and that it really does happen at > runtime. I'm still not seeing a disparity. The compiler interprets generic declarations and stores them in the class file. At runtime, those types are available to introspection but not checked for validity, a job already done at compile time. As you observed earlier, the problem is more subtle than my initial response. I welcome any clarification. -- John B. Matthews trashgod at gmail dot com