1

I want to use this enum structure in order to return string.

public enum Exchanges {

    PROCESSING("processing");

    private final String type;

    Exchanges(final String type) {
        this.type = type;
    }

    public String getType() {
        return type;
    }

    @Override
    public String toString() {
        return type;
    }
}

When I use Exchanges.PROCESSING I get error:

Syntax error, insert "VariableDeclarators" to complete 
 LocalVariableDeclaration

How I can fix this issue?

8
  • 2
    Exchanges e = Exchanges.PROCESSING should work fine. Please show your code. Commented Jun 14, 2018 at 10:07
  • Yes, but I want to use the code in case like this: channel.exchangeDeclare(Exchanges.PROCESSING, BuiltinExchangeType.TOPIC); Commented Jun 14, 2018 at 10:08
  • 3
    Please show minimal reproducible example Commented Jun 14, 2018 at 10:08
  • Please show use the code relative to channel.exchangeDeclare Commented Jun 14, 2018 at 10:08
  • 2
    Possible duplicate of Using Enum values as String literals Commented Jun 14, 2018 at 10:16

1 Answer 1

3
channel.exchangeDeclare(String exchange , BuiltinExchangeType obj)

should be

channel.exchangeDeclare(Exchanges exchange , BuiltinExchangeType obj)

or you should change the method call

channel.exchangeDeclare(Exchanges.PROCESSING, BuiltinExchangeType.TOPIC);

to

channel.exchangeDeclare(Exchanges.PROCESSING.getType(), BuiltinExchangeType.TOPIC);
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks but is there a way to call just Exchanges.PROCESSING without getType()
Well surely there is. And it returns you an object of type Exchanges. Which is not a String.
Then don't use an enum. Because that's not how an enum works.
Yes. As @Ben said, maybe you want to use constants, not enums.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.