Bug 538253 - Override a method with partially raw generic array argument results in compile error
Summary: Override a method with partially raw generic array argument results in compil...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.7.3   Edit
Hardware: PC Windows 7
: P4 major (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-24 10:08 EDT by Elisej Friedrich CLA
Modified: 2022-12-04 15:53 EST (History)
1 user (show)

See Also:


Attachments
The java files with the example from description. (545 bytes, application/x-zip-compressed)
2018-08-24 10:08 EDT, Elisej Friedrich CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Elisej Friedrich CLA 2018-08-24 10:08:05 EDT
Created attachment 275529 [details]
The java files with the example from description.

Trying to override a method with an argument which is a generic array of ? extends SomeGenericRawType leads to the following errors:

1.
Name clash: The method method(Class<? extends List>...) of type SubClass has the same erasure as method(Class<? extends List>...) of type BaseClass but does not override it

2.
The method method(Class<? extends List>...) of type SubClass must override or implement a supertype method

------
Here a small example:

public class BaseClass {

    public String method(Class<? extends List>... classes) {
        return null;
    }
}

public class SubClass extends BaseClass {

    @Override
    public String method(Class<? extends List>... classes) {
        return null;
    }
}

------
The compile errors would not apprear if the argument is not an array, so the <? extends RawType> seems to be allowed and considered, but not for arrays.

------
The oracle compiler has no problem with the example above.

------
When changing the example the following way (make List not being a raw type, List<?>), the .class file looks the same, but there are no compile errors:


public class BaseClass {

    public String method(Class<? extends List<?>>... classes) {
        return null;
    }
}

public class SubClass extends BaseClass {

    @Override
    public String method(Class<? extends List<?>>... classes) {
        return null;
    }
}
Comment 1 Stephan Herrmann CLA 2018-08-24 17:44:49 EDT
(In reply to Elisej Friedrich from comment #0)
> ------
> When changing the example the following way (make List not being a raw type,
> List<?>), the .class file looks the same, but there are no compile errors:
> 
> 
> public class BaseClass {
> 
>     public String method(Class<? extends List<?>>... classes) {
>         return null;
>     }
> }
> 
> public class SubClass extends BaseClass {
> 
>     @Override
>     public String method(Class<? extends List<?>>... classes) {
>         return null;
>     }
> }

That's the proper way of coding this. 

I not sure that the original mixture of arrays, generics, wildcards and raw types is sufficiently well defined in JLS, such that compilers come to the same conclusion. Please don't hold your breath waiting for this issue to be resolved.
Comment 2 Eclipse Genie CLA 2020-08-16 19:45:55 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 3 Eclipse Genie CLA 2022-12-04 15:53:12 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.