Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
69 views

When I'm developing a SpringBoot project, I find that I'm often need to write code to judge whether the parameters from the API are my expected attribute of the enum value or not. Such as: @Getter ...
0 votes
3 answers
54 views

I'm writing a class that is dependent on months and how many days each month has. At the beginning of my class, I've written: static final int JAN = 1; static final int FEB = 2; ... static ...
2226 votes
15 answers
1.1m views

I know that Java enums are compiled to classes with private constructors and a bunch of public static members. When comparing two members of a given enum, I've always used .equals(), e.g. public ...
Advice
0 votes
0 replies
23 views

I'm trying to generate a C# client from the OpenRouter OpenAPI spec: https://github.com/OpenRouterTeam/typescript-sdk/blob/main/.speakeasy/in.openapi.yaml Among other things there are some enums ...
1 vote
1 answer
104 views

Given the base class: public abstract class EnumType<TEnum, TValue> where TEnum : struct, IConvertible where TValue : struct { public abstract TEnum GetEnumValue(TValue value); } ...
260 votes
22 answers
317k views

I'm rebuilding an old Java project in Javascript, and realized that there's no good way to do enums in JS. The best I can come up with is: const Colors = { RED: Symbol("red"), BLUE: ...
4419 votes
35 answers
1.1m views

How can you enumerate an enum in C#? E.g., the following code does not compile: public enum Suit { Spades, Hearts, Clubs, Diamonds } public void EnumerateAllSuitsDemoMethod() { ...
149 votes
1 answer
116k views

In Python 3.4, we got an Enum lib in the standard library: enum. We can get a backport for enum that works with Python 2.4 to 2.7 (and even 3.1 to 3.3), enum34 in pypi. But we've managed to get along ...
2 votes
3 answers
175 views

The C++ Coding guidelines, Enum.3: Prefer class enums over “plain” enums contains following example: void Print_color(int color); enum Web_color { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF }; ...
0 votes
1 answer
236 views

In Java, I can work with enums like classes. For example, I can create enum's constructor that take a value and init enum's value and class static function values() to list all enum's values. How to ...
0 votes
2 answers
1k views

I'm tinkering a bit with Qt's meta-object system, and I've come across an issue with adding enum class to a meta-object. I have a struct that contain some variables, one of which is an enum class. #...
63 votes
6 answers
47k views

Does Perl have an enumeration type that adheres to best practices, or maybe more importantly, does it need one? The project I am working one uses strings all over the place to denote things that ...
0 votes
2 answers
154 views

Clang's -Wassign-enum diagnostic flag will trigger a warning when using an int whose value is out of scope of an enum's cases: typedef enum Foo { FooA, FooB, } Foo; void handleFoo(Foo foo); ...
6 votes
6 answers
5k views

Can Enum contains other Enum elements along with its own elements ? public enum CardSuit { spades, hearts, diamonds, clubs } public enum GameSuit { spades, // These ...
14 votes
3 answers
16k views

I am finding that all of my standard techniques for iterating over regular enums unfortunately do NOT work on enum classes since enum classes do not implicitly convert to integers. NOT a duplicate of ...
2 votes
4 answers
177 views

Is there any way to implement self-documenting enumerations in "standard SQL"? EXAMPLE: Column: PlayMode Legal values: 0=Quiet, 1=League Practice, 2=League Play, 3=Open Play, 4=...
7 votes
4 answers
7k views

I have an enum: pub enum BoxColour { Red, Blue, } I not only want to get this value as a string, but I want the value to be converted to lower case. This works: impl Display for BoxColour { ...
2 votes
3 answers
6k views

I'm trying to reproduce the following C enumeration list in Python: enum Id { NONE = 0, HEARTBEAT, //0x1 FLUID_TRANSFER_REQUEST, FLUID_TRANSFER_STATUS_MSG, FLUID_TRANSFER_ERROR_MSG, ...
1 vote
0 answers
49 views

I am in a scenario (that could be compared to writing an AST) where I compile multiple regex patterns that I want to reuse later, and for the sake of simplicity and readability I want to store them in ...
0 votes
5 answers
3k views

TypeScript has added the erasableSyntaxOnly flag, that doesn't let you use Enums. Have looked for several alternative options. Like: What's the best practice to implement an alternative to ...
3 votes
1 answer
70 views

I am writing a Python config script that creates an array of input files in a domain-specific language (DSL), so my use case is a bit unusual. In this scenario, we want medium-level users to be able ...
1 vote
1 answer
116 views

I've been using this enum alternative composition: const makeEnum = <const O extends Record<string, string>>(obj: O) => { return { map: obj, values: (Object.keys(obj)...
2 votes
2 answers
157 views

Niche optimization allows Rust to store data in the invalid bit patterns of a type. The only valid values of a bool are 0 and 1 (one bit). And Result only has two variants (one bit). So why does ...
44 votes
4 answers
83k views

I am using project lombok with my application. I was creating an enum. If I use @AllArgsConstructor annotation with my enum, it doesn't recognise the constructor, enum throws and error that it ...
3 votes
2 answers
292 views

My IntEnum class: class Role(IntEnum): client = 1 manager = 2 admin = 3 What I got in generated openapi.json: { enum: [1, 2, 3], title: "Role", type: "integer" } ...

1
2 3 4 5
458