innerbuilder icon indicating copy to clipboard operation
innerbuilder copied to clipboard

Feature: add option to use default JVM contructor if the constructor is empty

Open landtlord opened this issue 2 years ago • 0 comments

Can you add an option to use default JVM contructor if the constructor is empty

According to squid:S1186 is having a empty body method a coding anti-pattern.

This is behavior now:

        private String name;
        private int age;

        public Builder() {
        }

        public Builder withName(String name) {
            this.name = name;
            return this;
        }

        public Builder withAge(int age) {
            this.age = age;
            return this;
        }

        public Person build() {
            return new Person(this);
        }

and this is the requested result

        private String name;
        private int age;

        public Builder withName(String name) {
            this.name = name;
            return this;
        }

        public Builder withAge(int age) {
            this.age = age;
            return this;
        }

        public Person build() {
            return new Person(this);
        }

landtlord avatar Sep 12 '23 13:09 landtlord