[records] customized accessor returning subtype

Dmitry Bessonov dmitry.bessonov at oracle.com
Wed Dec 25 14:37:23 UTC 2019


Thank you very much for all the feedback.

Looks like compiler error message could be improved with a mention of the "identical to the declared type of the corresponding record component” requirement.

Filed https://bugs.openjdk.java.net/browse/JDK-8236544 <https://bugs.openjdk.java.net/browse/JDK-8236544>

dmitry

> On 9 Dec 2019, at 19:09, Dmitry Bessonov <dmitry.bessonov at oracle.com> wrote:
> 
> Is there any reason for not allowing a customized accessor to return rc subtype:
> 
> record R(Number number) {
>    public Integer number() {
>        return 42;
>    }
> }
> 
> Error: java: invalid accessor method in record R
>  (return type of accessor method number() is not compatible with type of record component number)
> 
> 
> dmitry
> 



More information about the amber-dev mailing list