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

@ToString over enum to incorporate enum field name #1916

Closed
wizzlerr opened this Issue Oct 23, 2018 · 1 comment

Comments

2 participants
@wizzlerr
Copy link

wizzlerr commented Oct 23, 2018

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.

@rspilker

This comment has been minimized.

Copy link
Collaborator

rspilker commented Nov 5, 2018

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

@rspilker rspilker closed this in 7e79316 Nov 5, 2018

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