简体   繁体   中英

Return String from enum

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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM