Files
prompts/clean_java_code_rules.md
2026-07-23 15:35:15 +08:00

12 lines
815 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Intro
如何书写干净的Java源码请遵照以下原则
- 请积极优先使用Lombok注解无需担心编译速度被拖慢。
- NULL值处理优先使用`Optional`而不是`if`
- 优先使用`Stream`而不是`for`循环。
- 如果`Stream``map`中的代码块超过5行单独写一个函数。
- 如果`Stream``map`中代码块需要一个中间对象,请优先使用`record`类型并且把record类源文件放到DTO目录下。
- 方法体内的行数不得超过20行超过行数请拆成多个方法。
- 构建`JavaBean`对象优先使用构造函数而不是单独写工具类只有3个以内的Bean对象应该提供一个全部参数的构造函数。
- 对于`Set`类型集合除非对排序有要求否则应该优先使用HashSet而不是LinkedHashSet。