Lombok: Add a @OverrideConstructors annotation

Created on 2 Feb 2017  路  4Comments  路  Source: projectlombok/lombok

It would be nice to have an @OverrideConstructors annotation. This annotation would create one constructor for each constructor of the super class. That is a common use case if you subclass classes with multiple constructors.

I would be willing to try my hand on a pull request if you deem this annotation useful.

duplicate

Most helpful comment

Sure:
Without Lombok:

public class CustomException extends Exception {

    public CustomException(String message) {
        super(message);
    }

    public CustomException(String message, Throwable throwable) {
        super(message, throwable);
    }

    public CustomException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }

    ...
}

With Lombok:

@OverrideConstructors
public class CustomException extends Exception {}

All 4 comments

Can you give a code example of with and without your annotation?

Sure:
Without Lombok:

public class CustomException extends Exception {

    public CustomException(String message) {
        super(message);
    }

    public CustomException(String message, Throwable throwable) {
        super(message, throwable);
    }

    public CustomException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }

    ...
}

With Lombok:

@OverrideConstructors
public class CustomException extends Exception {}

Issue #375

This requires resolution, not something lombok can do right now.

Was this page helpful?
0 / 5 - 0 ratings