Possible compiler bug
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Tue Oct 22 11:16:16 UTC 2019
The problem is that Derived.Inner extends Base.Inner - which is a raw type.
Because of that, Derived.Inner does not inherit 'map' with type
Map<Integer, Referenced> as you expect, but instead it inherits it raw
(Map). Hence the error.
To fix, you need to replace the extends clause of Derived.Inner to say
"extends Base<Derived.Inner>.Inner"
Maurizio
On 22/10/2019 12:11, Stefan Reich wrote:
> Hi, ok, the class relationships in this example are bit convoluted (I
> have them for a reason in the original source code), but I still don't
> see why it would fail to compile.
> import java.util.Map;
>
> class Referenced {
> }
>
> class Base<A extends Base.Inner> {
>
> class Inner {
> Map<Integer, Referenced>map;
>
> void bla() {
> Referenced r =map.get(0);
> }
> }
> }
>
> class Derivedextends Base<Derived.Inner> {
> class Innerextends Base.Inner {
> void bla() {
> Referenced r =map.get(0);
> }
> }
> }
> The error message is:
>
> Referenced.java:20: error: incompatible types: Object cannot be
> converted to Referenced
> Referenced r = map.get(0);
>
> Why does the map suddenly lose its type parameters?
>
> Many greetings,
> Stefan
>
> --
> Stefan Reich
> BotCompany.de // Java-based operating systems
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20191022/b099d785/attachment-0001.html>
More information about the compiler-dev
mailing list