The file `Report.java` below is a compact source file (JEP 512) — it declares no class, and it contains no `import` statements at all. It is launched directly with `java Report.java` on JDK 25.
```java
List<Integer> scores = List.of(70, 85, 90);
List<Integer> passing() {
return scores.stream().filter(s -> s >= 80).toList();
}
void main() {
IO.println("passed=" + passing());
}
```
What is the result?
A. Compilation fails: `IO` lives in `java.io` and must be imported before it can be used.
Misfiles the new console API: IO is java.lang.IO, so it needs no import anywhere — in a compact source file or an ordinary class — and the program compiles.
B. passed=[70, 85, 90]
The "filter does nothing until you collect" misconception; toList() is the terminal operation that consumes the filtered pipeline, not a plain conversion of the source list, so 70 is dropped.
C. Compilation fails: `cannot find symbol: class List` — a compact source file still needs `import java.util.List;`.
Incorrect for a compact source file: it gets an implicit import module java.base, so List resolves without an import line — that error would occur only if these lines were pasted into an ordinary class.
D. passed=[85, 90]Correct answer
Correct: a compact source file is compiled as if it began with import module java.base (pulling in java.util), and its top-level field and methods become members of an implicit class, so passing() filters to 85 and 90, printing passed=[85, 90].
Explanation
Trace: every compact source file is compiled as if it began with `import module java.base;`. That single implicit module import pulls in the exported packages of `java.base` — including `java.util` — so `List` and `List.of` resolve with no import line. `scores` is a top-level field, `passing()` is a top-level instance method, and both become members of the implicitly declared class, so `passing()` can read `scores` directly. The stream keeps 85 and 90 (both `>= 80`) and drops 70, and `toList()` renders as `[85, 90]`, giving `passed=[85, 90]`.
Why the others are wrong:
`Compilation fails: `cannot find symbol: class List` ...` encodes the belief that a compact source file gets only the ordinary `java.lang` auto-import, so `java.util` types must still be imported by hand. That is exactly the convenience JEP 512 removes — and the belief is *correct for an ordinary class*: paste these same lines into `public class Report { ... }` and `javac` really does report `cannot find symbol: class List`. The implicit module import is a property of the compact form, not of the file name.
`passed=[70, 85, 90]` is the "`filter` does nothing until you `collect`" misconception — the student treats `toList()` as a plain conversion of the source list rather than the terminal operation that consumes the filtered pipeline.
`Compilation fails: `IO` lives in `java.io` ...` is the very common misfiling of the new console API. `IO` is `java.lang.IO`, so it needs no import anywhere — in a compact source file *or* in an ordinary class.
Exam tip: a compact source file gets two things an ordinary class does not — an implicit `import module java.base` and an implicitly declared class wrapping its top-level members. It does **not** get a static import of `IO`'s methods, so you still write `IO.println(...)`, never a bare `println(...)`. Reverse trap: `var` is not allowed on a *field*, so a top-level `var scores = List.of(...)` in a compact source file fails with `'var' is not allowed here` — top-level declarations are fields, not local variables.