Lesson 25 / 25
Revision and Interview Questions
Recall Scala concepts quickly for exams and interviews.
Cheat sheet
Basics: OOP plus FP on the JVM (also Scala.js, Scala Native); Scala 3 with optional braces; val vs var; type inference; Any, AnyVal, AnyRef, Nothing, Unit; everything is an expression; string interpolators s, f, raw; lazy val. Tools: Coursier, Scala CLI (the scala command since 3.5, //> using directives), sbt (build.sbt, %% vs %, multi-module, ~test), Metals, IntelliJ. Control: if/match expressions, for comprehensions desugaring to map/flatMap/withFilter. Collections: immutable List, Vector, Map, Set, Range; groupMapReduce, foldLeft, collect, partition, views, LazyList. Functions: lambdas, placeholder _, higher-order functions, currying, by-name parameters, composition. OOP: classes, singleton and companion objects, traits, linearisation and stackable traits, sealed. ADTs: case classes (copy, value equality), enums, exhaustive matching. FP: pattern matching and extractors, Option/Either/Try, @tailrec, folds. Types: generics, variance (+A, -A), bounds (<:, >:), given/using, type classes and context bounds, extension methods, opaque types, union and intersection types. Concurrency: Futures and ExecutionContexts, Cats Effect and ZIO fibers, Pekko actors. Ecosystem: MUnit, ScalaTest, ScalaCheck, Spark, Play, http4s, Tapir, circe, Doobie, Java interop.
Common interview questions
Answer each with a short code example.
1. What does it mean that Scala combines OOP and FP?
2. val vs var vs lazy val?
3. What do case classes generate for you?
4. What is a companion object used for?
5. How does a for comprehension desugar?
6. Option vs Either vs Try: when do you use each?
7. Explain covariance and contravariance with examples.
8. What are given instances and using clauses? How do type classes work?
9. What is trait linearisation?
10. What does @tailrec guarantee?
11. Future vs Cats Effect IO or ZIO: what is the difference?
12. What are opaque types and why use them?Explain trade-offs
Strong Scala answers explain why: for example, why an ADT beats a String status, why Either beats exceptions for validation, or why a Future created inside a for comprehension runs sequentially.
Quick check: Which Scala 3 feature creates a distinct compile-time type with no runtime wrapper?
- case class
- trait
- lazy val
- opaque type
Answer
opaque type — Opaque type aliases erase to their underlying type at run time.