Groups | Search | Server Info | Keyboard shortcuts | Login | Register


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

Re: Java generics and type erasure

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!y31g2000vbp.googlegroups.com!not-for-mail
From Marcin Pietraszek <m.pietraszek@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Java generics and type erasure
Date Tue, 24 May 2011 12:39:45 -0700 (PDT)
Organization http://groups.google.com
Lines 38
Message-ID <332d40a8-689d-44bd-af0a-a7349aeb7217@y31g2000vbp.googlegroups.com> (permalink)
References <9d4c2b16-beb5-40b1-87a2-f03e971efeed@k17g2000vbn.googlegroups.com> <nospam-871A48.22542123052011@news.aioe.org> <irfgkl$lca$1@news.albasani.net>
NNTP-Posting-Host 78.8.137.62
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-Trace posting.google.com 1306265986 516 127.0.0.1 (24 May 2011 19:39:46 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Tue, 24 May 2011 19:39:46 +0000 (UTC)
Complaints-To groups-abuse@google.com
Injection-Info y31g2000vbp.googlegroups.com; posting-host=78.8.137.62; posting-account=KUK86woAAAA95Qsd_MUUhEi_C0vFO-Rj
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-Header-Order HUALESNKRC
X-HTTP-UserAgent Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1,gzip(gfe)
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:4546

Show key headers only | View raw


> John B. Matthews wrote:
>
> It's subtler than that.  The generic parameter is on 'Foo', not the map.  The
> map type does not depend on the type parameter.  So the question is why the
> 'get()' returns 'Object'.  Naively, one would expect the type of 'bar' to
> resolve to 'Map<String, Integer>' no matter what '<T>' is, or isn't.
>
> The only thing I can think of is that leaving the type parameter out in the
> containing class means that all bets are off, and the compiler gives up on
> generics throughout that variable's depth.  Thus it doesn't even bother to
> parse the 'bar' parameters, defaulting thus to '<?,?>'.  Consequently, the
> type of the expression 'foo2.bar.get("x")' is 'Object'.  The assignment target
> of that expression is 'Integer', and that requires an explicit downcast,
> omitted in the code along with the type parameter.
>
> This is an object lesson (pun intended) in how bad it really can be to omit
> the type parameter.
>
> I haven't looked up chapter and verse on this reasoning yet.  Anyone care to
> rise to the challenge?

To be honest before asking on group I've tried to search the answer in
JLS, unfortunatelly without any success -- I have same observations as
yours but I didn't manage to find exact explanation.

--
greegings
Marcin Pietraszek

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