Polyglot CheatSheet - enum

Updated: 2021-11-19

C++

According to Google C++ Style Guide, enumerators should be named like constants (like kOutOfMemory) instead of macros (OUT_OF_MEMORY ) to avoid conflicts.

enum class Color {
  kRed = 0,
  kBlue,
  kOrange,
};

Java

enum DayOfWeek {
  SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
}

Read more: Java Enum

ProtoBuf

enum Corpus {
  UNIVERSAL = 0;
  WEB = 1;
  IMAGES = 2;
  LOCAL = 3;
  NEWS = 4;
  PRODUCTS = 5;
  VIDEO = 6;
}