All fields

“Enums” in Information Technology

63 questions across 5 technologies.

Information Technology

63 questions in 5 technologies

#QuestionTechnologyTopicLevel
1What is 'reverse mapping' in numeric enums, and why don't string enums support it? TypeScript › EnumsTypeScriptEnumsIntermediate
2How does the EnumSet and EnumMap provide more efficient alternatives to HashSet<Enum> and HashMap<Enum, V> specifically for enum keys? Java › EnumsJavaEnumsIntermediate
3How does TypeScript's structural type checking treat two DIFFERENT numeric enums that happen to have the same underlying values? TypeScript › EnumsTypeScriptEnumsAdvanced
4How does Java implement enums under the hood at the bytecode level (extending java.lang.Enum), and what makes them inherently thread-safe and serialization-safe as singletons? Java › EnumsJavaEnumsAdvanced
5What are enums introduced in PHP 8.1, and how do backed enums differ from pure enums in terms of the values they can represent? PHP › PHP 8 Features (Attributes, Enums, Match, Nullsafe Operator)PHPPHP 8 Features (Attributes, Enums, Match, Nullsafe Operator)Intermediate
6How do you safely validate that an enum value received from external input (like deserialized JSON or a database) is actually a DEFINED member, given that enums don't enforce this by default? C# › Enums & FlagsC#Enums & FlagsAdvanced
7How do enums interact with generic constraints, and why has it historically been awkward to write generic, reusable flag-manipulation code? C# › Enums & FlagsC#Enums & FlagsAdvanced
8How can PHP 8's readonly properties, enums, and first class callable syntax be combined together to build more robust, immutable, and expressive domain models compared to earlier PHP versions? PHP › PHP 8 Features (Attributes, Enums, Match, Nullsafe Operator)PHPPHP 8 Features (Attributes, Enums, Match, Nullsafe Operator)Advanced
9How do enums, introduced in PHP 8.1, provide a more type safe alternative to using class constants for representing a fixed set of related values? PHP › Constants & SuperglobalsPHPConstants & SuperglobalsAdvanced
10What are PHP 8's enums, and how do they provide a more type safe alternative to using plain class constants for representing a fixed set of related values? PHP › Type Declarations & Strict TypesPHPType Declarations & Strict TypesAdvanced
11What is a numeric enum, and what values do its members get by default? TypeScript › EnumsTypeScriptEnumsBeginner
12What is a string enum, and how does it differ from a numeric enum? TypeScript › EnumsTypeScriptEnumsBeginner
13What is an enum in Java, and how does it differ from simply using a set of integer or String constants? Java › EnumsJavaEnumsBeginner
14How do you retrieve all constants of an enum type, and how would you iterate over them? Java › EnumsJavaEnumsBeginner
15What is a 'const enum' and how does it differ from a regular enum in the compiled output? TypeScript › EnumsTypeScriptEnumsIntermediate
16How do computed and constant enum members work when mixing string and numeric-style initialization? TypeScript › EnumsTypeScriptEnumsIntermediate
17How do you add fields, constructors, and methods to a Java enum, and how would you implement an enum representing planets with mass and radius that calculates surface gravity? Java › EnumsJavaEnumsIntermediate
18How would you implement an enum that also implements an interface, and what's the benefit of having different enum constants provide different behavior through a shared interface contract? Java › EnumsJavaEnumsIntermediate
19What are the ordinal() and name() methods on an enum constant, and why is relying on ordinal() for persistence or serialization considered dangerous? Java › EnumsJavaEnumsIntermediate
20How do you correctly use an enum as a switch statement/expression's target, and what changed with the introduction of arrow-style switch expressions (Java 14+) regarding exhaustiveness and fall-through? Java › EnumsJavaEnumsIntermediate
21What is the valueOf() method on an enum, and what happens when you pass a name that doesn't match any declared constant? Java › EnumsJavaEnumsIntermediate
22How would you use an enum to represent a fixed set of configuration keys combined with a shared lookup method, avoiding scattered String literal keys throughout a codebase? Java › EnumsJavaEnumsIntermediate
23Why do many style guides recommend using a union of string literal types instead of an enum in modern TypeScript? TypeScript › EnumsTypeScriptEnumsAdvanced
24How do you create a type-safe iteration over all values of a string enum? TypeScript › EnumsTypeScriptEnumsAdvanced
25What is an 'ambient enum' declared with 'declare enum', and when would you use one? TypeScript › EnumsTypeScriptEnumsAdvanced
26How would you model a set of flags/permissions using a numeric enum with bitwise values, and how do you check if a flag is set? TypeScript › EnumsTypeScriptEnumsAdvanced
27How would you implement the Strategy pattern using an enum with constant-specific method bodies, and how does this compare to a traditional interface-based Strategy implementation? Java › EnumsJavaEnumsAdvanced
28How would you use an EnumMap combined with a switch expression to implement a state machine, and what compile-time safety benefits does an exhaustive switch over an enum provide? Java › EnumsJavaEnumsAdvanced
29How would you implement a custom enum that also functions as a lookup table (mapping an external code to a constant), such as parsing an HTTP status code string into an enum constant, handling unknown values gracefully? Java › EnumsJavaEnumsAdvanced
30How would you implement a custom compareTo()-based ordering for an enum that differs from its natural declaration-order ordering, given Comparable's default implementation uses ordinal()? Java › EnumsJavaEnumsAdvanced
31How would you handle adding behavior to an enum where the number of constants might grow very large or needs to be data-driven rather than hardcoded at compile time, and why might a class-based registry be more appropriate in that scenario? Java › EnumsJavaEnumsAdvanced
32What is an enumeration (enum) in C++? C++ › Enums & Enum ClassesC++Enums & Enum ClassesBeginner
33What is an enum class (scoped enum) and why is it preferred? C++ › Enums & Enum ClassesC++Enums & Enum ClassesBeginner
34How do you assign specific values to enumerators? C++ › Enums & Enum ClassesC++Enums & Enum ClassesBeginner
35What is the difference between an enum and a set of #define constants? C++ › Enums & Enum ClassesC++Enums & Enum ClassesBeginner
36How do you specify the underlying type of an enum? C++ › Enums & Enum ClassesC++Enums & Enum ClassesIntermediate
37How do you convert between an enum class and its underlying integer? C++ › Enums & Enum ClassesC++Enums & Enum ClassesIntermediate
38Can you forward declare an enum, and what are the rules? C++ › Enums & Enum ClassesC++Enums & Enum ClassesIntermediate
39What are the scoping and name-collision advantages of enum class? C++ › Enums & Enum ClassesC++Enums & Enum ClassesIntermediate
40How do you implement type-safe bit flags with enum class? C++ › Enums & Enum ClassesC++Enums & Enum ClassesAdvanced
41How can you convert an enum to a string (reflection limitations)? C++ › Enums & Enum ClassesC++Enums & Enum ClassesAdvanced
42How do you declare an enum in C#, and what underlying type do its members have by default? C# › Enums & FlagsC#Enums & FlagsBeginner
43How do you convert between an enum value and its underlying numeric value, and between an enum and its string name? C# › Enums & FlagsC#Enums & FlagsBeginner
44What is the match expression introduced in PHP 8, and how does it improve upon the traditional switch statement? PHP › PHP 8 Features (Attributes, Enums, Match, Nullsafe Operator)PHPPHP 8 Features (Attributes, Enums, Match, Nullsafe Operator)Beginner
45What is the nullsafe operator introduced in PHP 8, and how does it simplify safely accessing a chain of potentially null properties or methods? PHP › PHP 8 Features (Attributes, Enums, Match, Nullsafe Operator)PHPPHP 8 Features (Attributes, Enums, Match, Nullsafe Operator)Beginner
46How do you create a 'flags' enum that supports combining multiple values using bitwise operations? C# › Enums & FlagsC#Enums & FlagsIntermediate
47How does the [Flags] attribute change the output of ToString() on a combined flags enum value? C# › Enums & FlagsC#Enums & FlagsIntermediate
48What is the performance consideration when using Enum.HasFlag() versus a direct bitwise AND check? C# › Enums & FlagsC#Enums & FlagsIntermediate
49What are PHP attributes introduced in PHP 8, and how do they provide a structured, native alternative to the older convention of using docblock comments for metadata? PHP › PHP 8 Features (Attributes, Enums, Match, Nullsafe Operator)PHPPHP 8 Features (Attributes, Enums, Match, Nullsafe Operator)Intermediate
50How do constructor property promotion, introduced in PHP 8, reduce boilerplate code when defining a class with several properties initialized directly through its constructor? PHP › PHP 8 Features (Attributes, Enums, Match, Nullsafe Operator)PHPPHP 8 Features (Attributes, Enums, Match, Nullsafe Operator)Intermediate
51How would you write an extension method to safely add or remove a specific flag from a [Flags] enum value without manual bitwise operators scattered throughout your code? C# › Enums & FlagsC#Enums & FlagsAdvanced
52How would you use pattern matching (switch expressions) with an enum, including exhaustiveness warnings from the compiler? C# › Enums & FlagsC#Enums & FlagsAdvanced
53How would you design an enum-based state machine using pattern matching to enforce valid state transitions at compile time or runtime? C# › Enums & FlagsC#Enums & FlagsAdvanced
54How do union types and intersection types in PHP 8 provide more expressive and precise type declarations than were previously possible? PHP › PHP 8 Features (Attributes, Enums, Match, Nullsafe Operator)PHPPHP 8 Features (Attributes, Enums, Match, Nullsafe Operator)Advanced
55How do you merge a namespace with an enum to add extra static-like helper functionality to that enum? TypeScript › Namespaces & Declaration MergingTypeScriptNamespaces & Declaration MergingIntermediate
56What is array destructuring in PHP, and how does the list function or short array syntax simplify extracting values from an array? PHP › Arrays in PHPPHPArrays in PHPIntermediate
57What are arrow functions introduced in PHP 7.4, and how do they simplify writing short closures compared to traditional anonymous functions? PHP › Closures & Anonymous FunctionsPHPClosures & Anonymous FunctionsIntermediate
58What is the difference between class constants and global constants, and how do you define and access a constant within a class? PHP › Constants & SuperglobalsPHPConstants & SuperglobalsIntermediate
59How does the Factory pattern help decouple object creation logic from the code that actually uses those objects? PHP › Design Patterns in PHPPHPDesign Patterns in PHPIntermediate
60What are named arguments introduced in PHP 8, and how do they improve the readability of function calls with many parameters? PHP › Functions & ScopePHPFunctions & ScopeIntermediate
61How does the readonly property modifier introduced in PHP 8.1 help enforce immutability for specific class properties? PHP › OOPPHPOOPIntermediate
62How do first class callable syntax and higher order functions in modern PHP support building flexible, composable, functional style code? PHP › Closures & Anonymous FunctionsPHPClosures & Anonymous FunctionsAdvanced
63How do function type declarations and return type declarations improve code reliability, and how does PHP handle nullable and union types in function signatures? PHP › Functions & ScopePHPFunctions & ScopeAdvanced