java - Getting the value of an enum field -


i have enumeration of byte values:

        public class bytemessage {              public enum messages {                 ack(0x01), chat(0x02), turn(0x02), waiting(0x03), rematch(0x04), double(0x05), loadrequest(0x06), loadcomplete(0x07),                 roll(0x08), dblacceptordecline(0x09), dblrecv(0x0a), alertpeernopossibles(0x0b), updatedies(0x0c),                 setturn(0x0d), setfirstroll(0x0e), calcpossibleindexes(0x0f), loadgamerequest(0x10), loadgamecomplete(0x11), pushstatustext(0x12),                 isdoublesowner(0x13);                  private final byte id;                  messages(int id) {                     this.id = (byte) id;                 }                  public byte getid() {                     return this.id;                 }             } 

in class have function:

            private void sendack()             {                 byte[] message = new byte[10];                  //neither 1 of these compile have return byte value of ack                 //byte = new byte(bytemessage.m.ack);                 //message[0] = bytemessage.m.ack; 

is there way byte value out of enum?

thank you!

you should use getid method of message enum :

message[0] = bytemessage.m.ack.getid(); 

each constant in enum instance of enum. classes, instance of enum can have data. in specific case, each enum constant has id initialized when enum constant created , can accessed through getid member method.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -