All fields

“Generics” in Information Technology

113 questions across 4 technologies.

Information Technology

113 questions in 4 technologies

#QuestionTechnologyTopicLevel
1What are generics in C#, and what specific problems do they solve compared to writing type-specific code? C# › GenericsC#GenericsIntermediate
2What are generics and why use them? C# › GenericsC#GenericsBeginner
3What problem do generics solve compared to using 'any' for a reusable function? TypeScript › GenericsTypeScriptGenericsBeginner
4What problem do generics solve compared to writing a method or class that accepts 'object'? C# › GenericsC#GenericsBeginner
5What problem do generics solve compared to using raw types (like a pre-Java-5 List without a type parameter), and how do they improve compile-time type safety? Java › GenericsJavaGenericsBeginner
6What is covariance and contravariance in generics? C# › GenericsC#GenericsIntermediate
7What is a raw type in Java, and why does the compiler still permit using them (with an unchecked warning) despite generics having been available since Java 5? Java › GenericsJavaGenericsIntermediate
8How are generics implemented for value types vs reference types in the CLR? C# › GenericsC#GenericsAdvanced
9How do generics interact with arrays, and why does the JDK itself sometimes use an unsafe cast (like in ArrayList's internal implementation) to work around the inability to create generic arrays directly? Java › GenericsJavaGenericsAdvanced
10How does variance (covariance, contravariance, invariance) apply differently to Java arrays versus Java generics, and what practical safety trade-off does this design difference represent? Java › GenericsJavaGenericsAdvanced
11What are generics in Dart, and how does declaring a collection like List<String> let the Dart compiler catch type related mistakes before your code even runs? Flutter › Dart Collections & GenericsFlutterDart Collections & GenericsBeginner
12How does exception handling interact with generics and type erasure, specifically regarding why you cannot catch a generic type parameter as an exception type (catch (T e))? Java › ExceptionsJavaExceptionsAdvanced
13How do you declare a generic type parameter on a function, and how do you explicitly specify it when calling? TypeScript › GenericsTypeScriptGenericsBeginner
14How do you declare a generic class with a type parameter, and how do you instantiate it with a specific type? C# › GenericsC#GenericsBeginner
15What are generic constraints and why are they needed? C# › GenericsC#GenericsIntermediate
16Why can't you use operators like + directly on an unconstrained generic T? C# › GenericsC#GenericsIntermediate
17How do you constrain a generic type parameter using 'extends' to require it has certain properties? TypeScript › GenericsTypeScriptGenericsIntermediate
18How do you use a generic type parameter to constrain a second parameter to be a valid key of the first? TypeScript › GenericsTypeScriptGenericsIntermediate
19How do you provide a default type for a generic parameter, similar to a default function parameter? TypeScript › GenericsTypeScriptGenericsIntermediate
20How do generic type constraints ('where T : ...') restrict what types can be used, and what are the common constraint kinds? C# › GenericsC#GenericsIntermediate
21How does generic type inference work when calling a generic method, and when do you need to specify the type argument explicitly? C# › GenericsC#GenericsIntermediate
22What is covariance ('out T') and contravariance ('in T') in generic interfaces, and how does IEnumerable<out T> demonstrate covariance? C# › GenericsC#GenericsIntermediate
23What is type erasure, and how does it explain why generic type information is unavailable at runtime (e.g., why you can't do `if (obj instanceof List<String>)`)? Java › GenericsJavaGenericsIntermediate
24How do you write a generic method (as opposed to a generic class), and how does the compiler infer the type parameter from the arguments passed at a call site? Java › GenericsJavaGenericsIntermediate
25What is an unbounded wildcard (List<?>), and when is it more appropriate to use than a bounded generic method with a type parameter <T>? Java › GenericsJavaGenericsIntermediate
26How would you implement a generic Stack<T> class from scratch, demonstrating how a self-contained generic data structure is typically structured? Java › GenericsJavaGenericsIntermediate
27How would you use a Class<T> token parameter to work around type erasure when a generic method genuinely needs runtime access to the actual type argument, such as for deserialization or reflection-based instantiation? Java › GenericsJavaGenericsIntermediate
28How would you write a generic interface (like a custom Repository<T, ID> pattern common in data-access layers) and implement it for a specific entity type? Java › GenericsJavaGenericsIntermediate
29What problem do generic math / static abstract interface members solve? C# › GenericsC#GenericsAdvanced
30How does generic type inference work across multiple arguments, and what happens when they conflict? TypeScript › GenericsTypeScriptGenericsAdvanced
31How do you write a generic class, and how do its type parameters interact with its constructor and methods? TypeScript › GenericsTypeScriptGenericsAdvanced
32How would you write a generic 'pick' utility function that mimics the built-in Pick<T, K> utility type, but as a runtime function with matching compile-time types? TypeScript › GenericsTypeScriptGenericsAdvanced
33What does 'variance' mean for generic types, and why does TypeScript's structural typing make some generic assignments unsound by default? TypeScript › GenericsTypeScriptGenericsAdvanced
34How would you implement a generic type-safe EventEmitter where each event name maps to its own specific payload type? TypeScript › GenericsTypeScriptGenericsAdvanced
35How would you implement a generic method with MULTIPLE type parameters and constraints that reference EACH OTHER, like a generic mapping function? C# › GenericsC#GenericsAdvanced
36How do generic type parameters interact with static members, and why does each closed generic type get its OWN independent set of static field values? C# › GenericsC#GenericsAdvanced
37How would you implement a generic, reusable object pool using generic constraints to ensure poolable objects can be properly reset? C# › GenericsC#GenericsAdvanced
38How do generic attributes (introduced in C# 11) work, and what limitation did they finally remove compared to older attribute usage patterns? C# › GenericsC#GenericsAdvanced
39How would you implement generic operator constraints using .NET's generic math interfaces (like INumber<T>) to write a single Sum<T>() method working across int, double, and decimal? C# › GenericsC#GenericsAdvanced
40How do bounded wildcards (? extends T and ? super T) work, and what does the PECS (Producer Extends, Consumer Super) mnemonic mean for choosing between them? Java › GenericsJavaGenericsAdvanced
41How would you implement a generic class with multiple type parameters and bounded type parameters (like <T extends Comparable<T>>), and what does this specific bound enable? Java › GenericsJavaGenericsAdvanced
42How does generic method overload resolution interact with type erasure to sometimes produce a compile error for seemingly valid overloads (like two methods differing only by their generic type parameter)? Java › GenericsJavaGenericsAdvanced
43How would you implement a generic builder pattern with a self-referential generic type parameter (the 'curiously recurring generic pattern', <T extends Builder<T>>) to support fluent method chaining that correctly returns the actual subclass type in an inheritance hierarchy? Java › GenericsJavaGenericsAdvanced
44How would you implement a generic pair/tuple utility method that returns different concrete types depending on the number of elements, and how does target-type inference help the compiler choose the correct generic instantiation from context alone? Java › GenericsJavaGenericsAdvanced
45What are the three main built in collection types in Dart, List, Set, and Map, and what makes each one uniquely suited for a different kind of data storage need? Flutter › Dart Collections & GenericsFlutterDart Collections & GenericsBeginner
46How do commonly used higher order collection methods, such as map, where, and reduce, let you transform and filter Dart collections in a clean, declarative style? Flutter › Dart Collections & GenericsFlutterDart Collections & GenericsIntermediate
47How do you create a custom generic class in Dart, and why would a generic class be preferable to writing several nearly identical, separate classes each hardcoded for a different specific type? Flutter › Dart Collections & GenericsFlutterDart Collections & GenericsIntermediate
48What are unmodifiable and immutable collections in Dart, and why might you deliberately choose to use one instead of a regular mutable collection in certain parts of your code? Flutter › Dart Collections & GenericsFlutterDart Collections & GenericsIntermediate
49How do bounded type parameters, using the extends keyword within a generic class definition, let you constrain a generic type to only accept types that satisfy a specific requirement? Flutter › Dart Collections & GenericsFlutterDart Collections & GenericsAdvanced
50What are the performance and memory tradeoffs between using a List, a LinkedHashMap, and a HashSet in Dart when working with a genuinely very large collection of data? Flutter › Dart Collections & GenericsFlutterDart Collections & GenericsAdvanced
51What is the basic syntax of a conditional type, and how does it resemble a ternary expression? TypeScript › Conditional TypesTypeScriptConditional TypesBeginner
52How do you write a type annotation for a function value, like a callback parameter? TypeScript › Function Types, Overloads & Optional/Default ParametersTypeScriptFunction Types, Overloads & Optional/Default ParametersBeginner
53How do you type an array of a specific element type, and what are the two equivalent syntaxes? TypeScript › Primitive Types, Arrays & TuplesTypeScriptPrimitive Types, Arrays & TuplesBeginner
54What is the difference between Where() and Select() in a LINQ query? C# › LINQC#LINQBeginner
55What is the Java Collections Framework, and what are the core interfaces (List, Set, Map, Queue) at its foundation? Java › Collections FrameworkJavaCollections FrameworkBeginner
56What is the difference between the Iterable and Iterator interfaces, and how does the enhanced for-each loop rely on them? Java › Collections FrameworkJavaCollections FrameworkBeginner
57What is a functional interface, and what are the four core functional interfaces in java.util.function (Function, Predicate, Consumer, Supplier)? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesBeginner
58What are the basic variable declaration keywords in Dart, specifically var, final, and const, and how do they differ from each other? Flutter › Dart Language Basics & SyntaxFlutterDart Language Basics & SyntaxBeginner
59What is null safety in Dart, and how does it help prevent a common category of runtime error known as a null reference exception? Flutter › Dart Null SafetyFlutterDart Null SafetyBeginner
60What is a Hive box, and how does it function as the basic fundamental storage unit specifically used for actually storing and retrieving your own particular data? Flutter › Hive & NoSQL Local StorageFlutterHive & NoSQL Local StorageBeginner
61What is JSON serialization and deserialization, and how do Dart's own built in jsonEncode and jsonDecode functions let you convert genuinely freely between a Dart object and its own corresponding JSON text representation? Flutter › JSON Serialization & DeserializationFlutterJSON Serialization & DeserializationBeginner
62How do labeled tuple elements improve readability and editor tooling compared to unlabeled tuples? TypeScript › Primitive Types, Arrays & TuplesTypeScriptPrimitive Types, Arrays & TuplesIntermediate
63When would you choose a HashSet<T> over a List<T>, and what guarantee does it provide? C# › CollectionsC#CollectionsIntermediate
64How do you write a generic extension method that works with any collection type, like a custom 'IsEmpty()' check? C# › Extension MethodsC#Extension MethodsIntermediate
65What is boxing and unboxing, and why does it have a real performance cost? C# › Memory & Garbage CollectionC#Memory & Garbage CollectionIntermediate
66How do multidimensional arrays work in Java, and how do they differ from truly rectangular arrays in languages like C? Java › Arrays & Multidimensional ArraysJavaArrays & Multidimensional ArraysIntermediate
67What utility methods does java.util.Arrays provide for common array operations like sorting, searching, filling, and comparing? Java › Arrays & Multidimensional ArraysJavaArrays & Multidimensional ArraysIntermediate
68How do you convert between an array and a List (ArrayList) in both directions, and what pitfalls exist with Arrays.asList()? Java › Arrays & Multidimensional ArraysJavaArrays & Multidimensional ArraysIntermediate
69How do you correctly iterate a 2D array using both traditional indexed for-loops and the enhanced for-each loop, and when is each approach preferable? Java › Arrays & Multidimensional ArraysJavaArrays & Multidimensional ArraysIntermediate
70What is array covariance's relationship to generic arrays, and why can't you directly create a generic array like new T[10] or new List<String>[10]? Java › Arrays & Multidimensional ArraysJavaArrays & Multidimensional ArraysIntermediate
71How does PriorityQueue work internally (as a binary heap), and what ordering does it use by default versus with a custom Comparator? Java › Collections FrameworkJavaCollections FrameworkIntermediate
72What is the relationship between equals() and the == operator when comparing primitive types versus reference types, and how does this affect comparing boxed wrapper types like Integer? Java › equals(), hashCode() & toString() ContractsJavaequals(), hashCode() & toString() ContractsIntermediate
73How does Comparable's compareTo() method relate to equals(), and what does it mean for compareTo() to be 'consistent with equals'? Java › equals(), hashCode() & toString() ContractsJavaequals(), hashCode() & toString() ContractsIntermediate
74How do the default methods andThen() and compose() on Function work, and what's the difference between them for chaining transformations? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesIntermediate
75What is the difference between UnaryOperator<T> and Function<T,T>, and why does UnaryOperator exist as a separate, more specific interface? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesIntermediate
76Can a local class or anonymous class be generic, and how does its own type parameter interact with any generic type parameters already declared on its enclosing class or method? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesIntermediate
77What are named parameters and positional parameters in Dart functions, and how does using curly braces to declare parameters as named improve the readability of a function call with many arguments? Flutter › Dart Language Basics & SyntaxFlutterDart Language Basics & SyntaxIntermediate
78What are extension methods in Dart, and how do they let you add new useful functionality directly onto an existing class, including classes you did not originally write yourself, such as Dart's own built in String class? Flutter › Dart Language Basics & SyntaxFlutterDart Language Basics & SyntaxIntermediate
79What do the null aware operators, specifically the null coalescing operator and the null aware access operator, actually do, and how do they let you write more concise code when working with nullable values? Flutter › Dart Null SafetyFlutterDart Null SafetyIntermediate
80How does Dart's late keyword let you declare a non nullable variable that will genuinely be initialized before it is ever actually first used, even though it cannot be given an initial value immediately at the exact point of its declaration? Flutter › Dart Null SafetyFlutterDart Null SafetyIntermediate
81How do provider dependencies and provider composition work in Riverpod, letting one provider genuinely and cleanly depend on the current value of a completely separate other provider? Flutter › Flutter Riverpod Code Generation & ProvidersFlutterFlutter Riverpod Code Generation & ProvidersIntermediate
82How does properly using TextInputFormatter genuinely help restrict or automatically format exactly what a user can actually type into a specific given text field, such as automatically formatting a phone number or restricting input to only numeric digits? Flutter › Forms & Input Validation in FlutterFlutterForms & Input Validation in FlutterIntermediate
83How do you properly store a genuinely fully custom Dart object, rather than simply a basic primitive type, within Hive using a generated TypeAdapter? Flutter › Hive & NoSQL Local StorageFlutterHive & NoSQL Local StorageIntermediate
84How do you properly handle deserializing a genuinely nested JSON structure, such as an order object that itself contains an embedded nested list of individual line item objects, into a properly correctly structured set of nested Dart model classes? Flutter › JSON Serialization & DeserializationFlutterJSON Serialization & DeserializationIntermediate
85How do you actually properly pass genuinely complex data types, such as a Map or a List, between Dart and native code through a platform channel, and what specific limitations genuinely exist regarding exactly what data can actually genuinely be sent? Flutter › Platform Channels (Native Android & iOS Integration)FlutterPlatform Channels (Native Android & iOS Integration)Intermediate
86How does StateNotifierProvider let you properly manage genuinely more complex state that requires several genuinely separate distinct methods for updating it, compared to the considerably simpler StateProvider? Flutter › State Management with RiverpodFlutterState Management with RiverpodIntermediate
87How does the 'protected constructor' pattern enforce a specific object-creation approach, like the Factory pattern? TypeScript › Classes: Access Modifiers, Abstract Classes & ImplementsTypeScriptClasses: Access Modifiers, Abstract Classes & ImplementsAdvanced
88How would you write a conditional type that recursively flattens a nested array type of arbitrary depth? TypeScript › Conditional TypesTypeScriptConditional TypesAdvanced
89How do parameter decorators work, and what is a common real-world use for them? TypeScript › DecoratorsTypeScriptDecoratorsAdvanced
90How do you write a generic Result<T, E> discriminated union type for functional-style error handling, and why is it preferred over throwing exceptions in some codebases? TypeScript › Discriminated Unions & Exhaustiveness CheckingTypeScriptDiscriminated Unions & Exhaustiveness CheckingAdvanced
91How would you type a higher-order function that accepts a function and returns a new function with an additional, injected parameter removed from its signature? TypeScript › Function Types, Overloads & Optional/Default ParametersTypeScriptFunction Types, Overloads & Optional/Default ParametersAdvanced
92How would you implement a type-safe 'groupBy' function whose return type is a Record keyed by the actual grouping values encountered? TypeScript › Index Signatures & Record TypesTypeScriptIndex Signatures & Record TypesAdvanced
93How would you write a generic type that extracts the length of a tuple type at compile time? TypeScript › Primitive Types, Arrays & TuplesTypeScriptPrimitive Types, Arrays & TuplesAdvanced
94How do variadic tuple types (using generic rest elements) let you build type-safe function composition or concat utilities? TypeScript › Primitive Types, Arrays & TuplesTypeScriptPrimitive Types, Arrays & TuplesAdvanced
95How do generic type parameters complicate structural comparisons, particularly regarding 'bivariant' method comparison? TypeScript › Structural Typing & Duck TypingTypeScriptStructural Typing & Duck TypingAdvanced
96How would you write a simple reflection-based object mapper that copies matching property values from one object to another of a different type? C# › Attributes & ReflectionC#Attributes & ReflectionAdvanced
97Why is reflection generally slower than direct code, and what techniques (like caching or compiled expressions) mitigate this cost? C# › Attributes & ReflectionC#Attributes & ReflectionAdvanced
98How would you choose between List<T>, LinkedList<T>, and ImmutableList<T> based on their different Big-O characteristics for common operations? C# › CollectionsC#CollectionsAdvanced
99How do delegate covariance and contravariance work with method group conversions in C#? C# › Delegates, Events & LambdasC#Delegates, Events & LambdasAdvanced
100How 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
101How do you correctly implement IComparable<T> alongside IEquatable<T>, and what consistency rule must they both satisfy together? C# › Equality: Equals, GetHashCode & IEquatableC#Equality: Equals, GetHashCode & IEquatableAdvanced
102How would you write generic extension methods leveraging C# 11's generic math interfaces (like INumber<T>) to build a single reusable numeric utility working across int, double, decimal, and other numeric types? C# › Extension MethodsC#Extension MethodsAdvanced
103How do target-typed 'new' expressions work, and what ambiguity do they resolve compared to always specifying the type twice? C# › FundamentalsC#FundamentalsAdvanced
104How do static abstract interface members (C# 11+) enable generic math and other 'static polymorphism' patterns? C# › Interfaces & Abstract ClassesC#Interfaces & Abstract ClassesAdvanced
105How do type annotations (introduced in Java 8, JSR 308) differ from traditional declaration annotations, and what new locations can they target? Java › AnnotationsJavaAnnotationsAdvanced
106How does Java implement covariant array typing, and why is this considered a design flaw that can lead to runtime ArrayStoreException? Java › Arrays & Multidimensional ArraysJavaArrays & Multidimensional ArraysAdvanced
107How would you implement a custom, resizable dynamic array (similar to ArrayList's internal mechanism) from scratch using a raw Java array, including the amortized doubling growth strategy? Java › Arrays & Multidimensional ArraysJavaArrays & Multidimensional ArraysAdvanced
108How does TreeMap/TreeSet's red-black tree implementation guarantee O(log n) operations, and what role does the Comparable/Comparator interface play in maintaining sorted order? Java › Collections FrameworkJavaCollections FrameworkAdvanced
109How would you implement a custom functional interface with generic type parameters, and what considerations apply when designing one instead of reusing a built-in java.util.function interface? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesAdvanced
110How does the var keyword (local variable type inference, introduced in Java 10) work, and what specific restrictions apply to where it can and cannot be used, given Java remains a statically-typed language? Java › Java Fundamentals: Syntax, Data Types & OperatorsJavaJava Fundamentals: Syntax, Data Types & OperatorsAdvanced
111How 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
112What are Dart records, and how do they let you group together several distinct values of potentially different types without needing to first define an entirely separate dedicated class? Flutter › Dart Language Basics & SyntaxFlutterDart Language Basics & SyntaxAdvanced
113How do you properly write parameterized tests that run the exact same test logic against several genuinely different sets of input data, avoiding needing to duplicate that exact same test method several genuinely separate times? Flutter › Unit Testing in FlutterFlutterUnit Testing in FlutterAdvanced