Skip to content

@ToString over enum to incorporate enum field name #1916

Closed
@wizzlerr

Description

@wizzlerr

Tested on 1.18.2 and 1.16.18

@ToString
enum SampleEnum {
    SOME_FIELD;
}

Currently above enum is compiled into below code.

enum SampleEnum {
    SOME_FIELD;

 public String toString() {
        return "SampleEnum ()";
    }
}

So whenever i run toString on List I will get N "SampleEnum()" strings.

It should be compiled to:

enum SampleEnum {
    SOME_FIELD;

 public String toString() {
        return "SampleEnum (name())";
    }
}

or anything that indicates enums field name.

Activity

rspilker

rspilker commented on Nov 5, 2018

@rspilker
Collaborator

I suggest to use return "SampleEnum." + name() + "()";

rzwitserloot

rzwitserloot commented on Jan 29, 2019

@rzwitserloot
Collaborator

this is now available in edge release: https://projectlombok.org/download-edge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @rzwitserloot@rspilker@wizzlerr

        Issue actions

          @ToString over enum to incorporate enum field name · Issue #1916 · projectlombok/lombok