7 questions for “Pattern Matching & Switch Expressions”

Found in 1 field. Select a question to see its full answer.

Information Technology

7 questions in 3 technologies

#QuestionTechnologyTopicLevel
1How would you implement the Visitor pattern in Java to add new operations to an existing class hierarchy without modifying those classes, and how do Java's sealed classes and pattern matching (switch expressions) provide a modern alternative? Java › Design Patterns in JavaJavaDesign Patterns in JavaAdvanced
2How would you use pattern matching (switch expressions) with an enum, including exhaustiveness warnings from the compiler? C# › Enums & FlagsC#Enums & FlagsAdvanced
3How does pattern matching, introduced through Dart's more modern switch expressions and destructuring, let you write more concise and expressive code when handling different possible shapes of data? Flutter › Dart Language Basics & SyntaxFlutterDart Language Basics & SyntaxAdvanced
4How 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
5What is the difference between a compile-time constant expression and a regular final variable, and why does this distinction matter for switch statement case labels and certain compiler optimizations? Java › Java Fundamentals: Syntax, Data Types & OperatorsJavaJava Fundamentals: Syntax, Data Types & OperatorsIntermediate
6How 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
7How would you design a sealed interface (Java 17+) to restrict which classes are permitted to implement it, and what benefit does this provide over a traditional open (unrestricted) interface for exhaustiveness checking? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesAdvanced