Lecture 3 — Part 1: The SAM Rule (Gamified)
You’re learning the rule behind Java lambdas: a “Functional Interface” must have exactly ONE method with a missing body. Default/static methods don’t count because they already have bodies.
Missing Body Rule = “abstract method”Default/static = ignored by SAM count@FunctionalInterface = safety net (optional, recommended)
The SAM Police 🚓
Count only “missing body” methods. Exactly one = valid.
Score
0
Scenario A: One Missing Body
Case 1 / 3
Is this a valid Functional Interface?
Evidence (Interface Snippet)
interface Calculator {
int add(int a, int b); // Missing body => counts
}Rule Hint
Missing Body Rule: only methods without bodies are counted.
Remember: Exactly ONE missing-body method + any number of default/static methods.
The Safety Shield 🛡️
Toggle @FunctionalInterface to see compiler enforcement.
Interface Under Inspection (intentionally broken)
Code
interface Calculator {
int add(int a, int b); // Missing body => counts
int subtract(int a, int b); // Missing body => counts (breaks SAM)
}What’s happening?
The annotation is optional, but it’s a safety net: “I promise this interface will stay at exactly ONE missing-body method.”
Default/static methods have bodies, so they don’t count toward the SAM total.
Sign In to Keep Going
You've reached the end of the free preview. Sign in — and upgrade to Plus or Pro — to keep going with DataStructure.
Full Access
Unlock all 13 lessons