Possible compiler bug

Stefan Reich stefan.reich.maker.of.eye at googlemail.com
Tue Oct 22 11:19:55 UTC 2019


I was confused because the map's type parameters have nothing to do with
either the base, derived or enclosing classes.

Be that as it may, your fix works. Thanks!

On Tue, 22 Oct 2019 at 13:18, Stefan Reich <
stefan.reich.maker.of.eye at googlemail.com> wrote:

> Hmm... so you're saying all the fields in a base class lose their type
> parameters when I inherit from the raw base class? That's quite surprising
> actually.
>
> On Tue, 22 Oct 2019 at 13:16, Maurizio Cimadamore <
> maurizio.cimadamore at oracle.com> wrote:
>
>> 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 Derived extends Base<Derived.Inner> {
>>     class Inner extends 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
>>
>>
>
> --
> Stefan Reich
> BotCompany.de // Java-based operating systems
>


-- 
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/55654f26/attachment.html>


More information about the compiler-dev mailing list