Java Distiller
Transform Java code into its cleanest, most modern, idiomatic form. Distill away verbosity, legacy patterns, and accidental complexity — keep only the essence.
Philosophy
- Distill, don't decorate — remove complexity, don't add abstractions
- Modern Java first — use Java 21+ features wherever they simplify the code
- Functional over imperative — prefer streams, lambdas, and declarative style when clearer
- Less code, more meaning — every remaining line should earn its place
- Preserve exact behavior — distilling is refactoring, not rewriting
Workflow
- Read the input code carefully
- Identify transformation opportunities (see references/transformations.md)
- Apply transformations — prioritize those with the highest impact-to-risk ratio
- Present the distilled code with a brief explanation of what changed and why
Transformation Priority
Apply in this order — high-impact, low-risk first:
- Syntax modernization —
var, text blocks, switch expressions, pattern matching, module imports
- API upgrades —
java.time, java.nio.file, HttpClient, List.of/Map.of, Optional, Stream
- Pattern adoption — records, sealed interfaces, pattern matching for
instanceof and switch
- Functional style — streams over loops, lambdas over anonymous classes, method references
- Concurrency modernization — virtual threads, structured concurrency, scoped values (only when the codebase already uses them or the target JDK supports them)
- Structural simplification — flatten hierarchies, inline trivial methods, remove dead code
Output Format
## Distilled Java Code
```java
// transformed code
```
### Changes
- <what changed> — <why it's better>
- ...
Rules
- Preserve behavior exactly — distilling is refactoring, not rewriting
- Do not add comments, Javadoc, or logging that wasn't there
- Do not add error handling beyond what exists unless the original code has a bug
- Do not introduce new dependencies
- Remove unnecessary blank lines, redundant modifiers, and dead imports
- Use
var where the type is obvious from the right-hand side
- Use module imports (
import module java.net.http;) over individual type imports when the target JDK supports them
- Prefer
void main() over public static void main(String[] args) when appropriate
- When multiple transformations compete, choose the one that produces fewer lines
- If the code is already clean and modern, say so — don't force changes
- Respect the project's target Java version; do not introduce preview features unless explicitly enabled
Detailed Transformation Catalog
See references/transformations.md for the complete catalog of before/after transformation patterns organized by category.
1---2name: java-distiller3description: Simplify, modernize, refactor, and beautify Java code to produce clean, idiomatic Java. Use when asked to distill, simplify, modernize, upgrade, refactor, clean up, beautify, or improve Java code. Triggers on "distill this Java", "modernize this code", "simplify this Java", "upgrade to modern Java", "refactor to Java 21+", "clean up this code", "make this idiomatic", "beautify this Java", or when Java code needs transformation to current standards. Not for writing new code from scratch — use an appropriate Java development skill for that.4---56# Java Distiller78Transform Java code into its cleanest, most modern, idiomatic form. Distill away verbosity, legacy patterns, and accidental complexity — keep only the essence.910## Philosophy1112- **Distill, don't decorate** — remove complexity, don't add abstractions13- **Modern Java first** — use Java 21+ features wherever they simplify the code14- **Functional over imperative** — prefer streams, lambdas, and declarative style when clearer15- **Less code, more meaning** — every remaining line should earn its place16- **Preserve exact behavior** — distilling is refactoring, not rewriting1718## Workflow19201. Read the input code carefully212. Identify transformation opportunities (see [references/transformations.md](references/transformations.md))223. Apply transformations — prioritize those with the highest impact-to-risk ratio234. Present the distilled code with a brief explanation of what changed and why2425## Transformation Priority2627Apply in this order — high-impact, low-risk first:28291. **Syntax modernization** — `var`, text blocks, switch expressions, pattern matching, module imports302. **API upgrades** — `java.time`, `java.nio.file`, `HttpClient`, `List.of`/`Map.of`, `Optional`, `Stream`313. **Pattern adoption** — records, sealed interfaces, pattern matching for `instanceof` and `switch`324. **Functional style** — streams over loops, lambdas over anonymous classes, method references335. **Concurrency modernization** — virtual threads, structured concurrency, scoped values (only when the codebase already uses them or the target JDK supports them)346. **Structural simplification** — flatten hierarchies, inline trivial methods, remove dead code3536## Output Format3738````markdown39## Distilled Java Code4041```java42// transformed code43```4445### Changes46- <what changed> — <why it's better>47- ...48````4950## Rules5152- Preserve behavior exactly — distilling is refactoring, not rewriting53- Do not add comments, Javadoc, or logging that wasn't there54- Do not add error handling beyond what exists unless the original code has a bug55- Do not introduce new dependencies56- Remove unnecessary blank lines, redundant modifiers, and dead imports57- Use `var` where the type is obvious from the right-hand side58- Use module imports (`import module java.net.http;`) over individual type imports when the target JDK supports them59- Prefer `void main()` over `public static void main(String[] args)` when appropriate60- When multiple transformations compete, choose the one that produces fewer lines61- If the code is already clean and modern, say so — don't force changes62- Respect the project's target Java version; do not introduce preview features unless explicitly enabled6364## Detailed Transformation Catalog6566See [references/transformations.md](references/transformations.md) for the complete catalog of before/after transformation patterns organized by category.