All fields

“Functional Interfaces & Method References” in Information Technology

27 questions across 2 technologies.

Information Technology

27 questions in 2 technologies

#QuestionTechnologyTopicLevel
1How would you convert a checked-exception-throwing method into a lambda usable with a standard functional interface (which doesn't declare any checked exceptions), given standard interfaces like Function don't permit checked exceptions in their abstract method signature? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesIntermediate
2How does Java's type inference determine the target type for a lambda expression in an ambiguous overload scenario, and what happens when a lambda could match multiple overloaded methods accepting different functional interfaces? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesAdvanced
3What 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
4What are the four kinds of method references in Java (static, instance-bound, instance-unbound, and constructor), and how does the compiler determine which form applies? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesIntermediate
5How do the primitive-specialized functional interfaces (IntFunction, ToIntFunction, IntPredicate, IntUnaryOperator, etc.) avoid the performance cost of autoboxing, and when should you prefer them over the generic equivalents? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesIntermediate
6How would you design a fluent, chainable validation API using functional interfaces, similar to how Comparator's thenComparing() works, but for validation rules that accumulate error messages rather than short-circuiting on the first failure? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesAdvanced
7How 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
8How 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
9How does the Predicate interface's default methods and(), or(), and negate() enable composing complex boolean conditions from simpler ones? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesIntermediate
10How would you use BiFunction combined with Stream's reduce() to implement a custom aggregation, and how does this relate to the more general concept of a fold operation in functional programming? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesAdvanced
11How do lambda expressions get compiled at the bytecode level using invokedynamic, and how does this differ from how an anonymous inner class implementing the same functional interface would be compiled? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesAdvanced
12What 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
13What is the difference between a Consumer<T> and a BiConsumer<T,U>, and how would you use BiConsumer for operations needing two inputs but no return value, such as Map.forEach()? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesIntermediate
14How does a lambda expression capture variables from its enclosing scope, and why must captured local variables be effectively final? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesAdvanced
15How would you implement memoization (caching function results) as a higher-order function wrapping an existing Function, and what thread-safety considerations apply for a memoized function used concurrently? Java › Functional Interfaces & Method ReferencesJavaFunctional Interfaces & Method ReferencesAdvanced
16How would you use an interface with only static and default methods (no abstract methods at all) to build a fluent, extensible utility API, and what's a real JDK example of this pattern? Java › Interfaces & Abstract ClassesJavaInterfaces & Abstract ClassesAdvanced
17What is the Strategy pattern, and how do Java 8's functional interfaces and lambdas make implementing it significantly more concise than the traditional interface-plus-implementation-classes approach? Java › Design Patterns in JavaJavaDesign Patterns in JavaIntermediate
18How would you implement a callback or event listener using an anonymous class, and how does this same use case increasingly get replaced by lambda expressions for functional interfaces in modern Java? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesIntermediate
19What is a delegate in C#, and how does it enable passing methods as values? C# › Delegates, Events & LambdasC#Delegates, Events & LambdasBeginner
20What is the purpose of the @FunctionalInterface annotation, and is it required for an interface to actually be treated as a functional interface? Java › AnnotationsJavaAnnotationsIntermediate
21How 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
22How 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
23How 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
24What is a local class's access to effectively-final local variables, and how does this same rule (and the underlying reason for it) apply identically to anonymous classes and lambdas? Java › Inner Classes & Anonymous ClassesJavaInner Classes & Anonymous ClassesIntermediate
25How would you use TemporalAdjusters to compute dates like 'the next Monday' or 'the last day of the month' relative to a given LocalDate? Java › Java Date & Time API (java.time)JavaJava Date & Time API (java.time)Intermediate
26How would you implement a custom Comparator with multiple sort criteria (e.g., sort by last name, then by first name as a tiebreaker) using the Comparator.comparing() and thenComparing() fluent API? Java › Collections FrameworkJavaCollections FrameworkAdvanced
27How 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