How should multiple value thrift of Java enumeration class be defined?

62 Views Asked by At
# java
public class B extends Enum implements TEnum {
    B a = new B("a", 1, 1);
    B b = new B("b", 2, 5);

    int val;

    public B(String s, int i, int val) {
        super(s, i);
        this.val = val;
    }
}

How should I define the above structure in thrift?

1

There are 1 best solutions below

0
JensG On

In Thrift an enum is simply an integer. It's not possible to have more complex structures on top of it.

 enum Foo {
      Bar = 0
      Baz = 1
      AnswerToEverythingEtc = 42     
 }

Remember that Thrift is compatible to 20+ target languages and dialects and most environments do not have the capability to do such stuff like having two values on an enum. To model that with Thrift consider using a struct

 struct TwoValues {
      1: i32 ord
      2: i32 val
 }