Skip to content

Make setters return this to allow for fluent interfaces #623

@greg-at-moderne

Description

@greg-at-moderne

What problem are you trying to solve?

Nicer APIs.

Describe the situation before applying the recipe

public class Person {
    private int age;

    public void setAge(int age) {
        this.age = age;
    }
}

Describe the situation after applying the recipe

public class Person {
    private int age;

    public Person setAge(int age) {
       this.age = age;
       return this; // <--------------
    }
}

Any additional context

  • One could consider doing the same to other methods returning void, not only the setters.
  • I haven't thought it through though, maybe some heuristics is needed to pick which methods it would be relevant for.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Recipes Wanted

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions