Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] @Accessors doesn't support inherted class well #3273

Open
asngeo opened this issue Oct 4, 2022 · 2 comments
Open

[BUG] @Accessors doesn't support inherted class well #3273

asngeo opened this issue Oct 4, 2022 · 2 comments

Comments

@asngeo
Copy link

asngeo commented Oct 4, 2022

Describe the bug
The @accessors doesn't support inherted class well. It can't return the subclass type when calling a setter of superclass on a subclass instance.

To Reproduce
For example, there are two classes:

@Data
@Accessors(fluent = true, chain = true)
class Parent {
    private int id;
}

@Data
@Accessors(fluent = true, chain = true)
class Child extends Parent {
    private String name;
}

I can't do such things: new Child().id(1).name("name"); because the definition of the id setter actually is: public Parent id(int id).

Expected behavior
I hope the usage like new Child().id(1).name("name"); can work. I think that we can use covarient type to override the chain-setters in subclasses just like public Child id(int id).

Version info (please complete the following information):

  • Lombok version: 1.18.22
  • Platform: jdk1.8

Thanks,
Geo

@asngeo
Copy link
Author

asngeo commented Oct 18, 2022

Could anyone take a look for this issue? Many thanks!

@janrieke
Copy link
Contributor

janrieke commented Oct 18, 2022

It's not possible at the moment.

Either you need resolution to find out which methods to override in a subclass, or some sophisticated concept of a SELF type that you can use as return type for the chainable setter methods. Both do not exist in Lombok and will probably not in the foreseeable future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants