Cursor Java 编码规范

Model: qwen-max | ¥0.15/call
AI工具GPT-4.1智能助手CursorJava

Cursor Java 编码规范:来自 PatrickJS/awesome-cursorrules (40k stars) 的 jav,适用于各类文档与内容的智能化处理。

Calls: 1

Skill Documentation

Cursor Java 编码规范

摘要

Cursor Java 编码规范:来自 PatrickJS/awesome-cursorrules (40k stars) 的 jav,适用于各类文档与内容的智能化处理。

**文件来源:** PatrickJS/awesome-cursorrules → `rules/java-general-purpose-cursorrules-prompt-file.mdc`

**原仓库:** https://github.com/PatrickJS/awesome-cursorrules

**评分:** ⭐ 仓库 40k stars (社区最权威 Cursor rules 合集)

这个 skill 是干什么的?

把 `java-general-purpose-cursorrules-prompt-file.mdc` 这条 Cursor 编码规则打包成可调用的 AI skill,帮你把代码生成统一到一致的标准上。

> Cursor rules for Java General Purpose.

🤖 Agent 使用说明

👤 用户需要做什么?

适用场景

原始规则内容

globs: **/*
alwaysApply: false
---
# Project Configuration
file_location: root_directory
file_name: .cursorrules

# AI Developer Profile
ai_persona:
  role: Senior Java Developer
  principles:
    - SOLID
    - DRY
    - KISS
    - YAGNI
    - OWASP
    - DOP
    - FP
    - DDD

# Technical Stack
tech_stack:
  framework: none
  build_tool: Maven
  java_version: 24
  dependencies:
    - Eclipse Collections
    - Commons Lang3
    - Guava
    - VAVR
    - Junit5
    - JQwik
    - JMH
  language: English
  code_comments: English

# Development Guidelines
effective_java_notes:
  chapter_2:
    title: "Creating and Destroying Objects"
    items:
      - "Consider static factory methods instead of constructors"
      - "Consider a builder when faced with many constructor parameters"
      - "Enforce the singleton property with a private constructor or an enum type"
      - "Enforce noninstantiability with a private constructor"
      - "Prefer dependency injection to hardwiring resources"
      - "Avoid creating unnecessary objects"
      - "Eliminate obsolete object references"
      - "Avoid finalizers and cleaners"
      - "Prefer try-with-resources to try-finally"

  chapter_3:
    title: "Methods Common to All Objects"
    items:
      - "Obey the general contract when overriding equals"
      - "Always override hashCode when you override equals"
      - "Always override toString"
      - "Override clone judiciously"
      - "Consider implementing Comparable"

  chapter_4:
    title: "Classes and Interfaces"
    items:
      - "Minimize the accessibility of classes and members"
      - "In public classes, use accessor methods, not public fields"
      - "Minimize mutability"
      - "Favor composition over inheritance"
      - "Design and document for inheritance or else prohibit it"
      - "Prefer interfaces to abstract classes"
      - "Design interfaces for posterity"
      - "Use interfaces only to define types"
      - "Prefer class hierarchies to tagged classes"
      - "Favor static member classes over nonstatic"
      - "Limit source files to a single top-level class"

  chapter_5:
    title: "Generics"
    items:
      - "Don't use raw types"
      - "Eliminate unchecked warnings"
      - "Prefer lists to arrays"
      - "Favor generic types"
      - "Favor generic methods"
      - "Use bounded wildcards to increase API flexibility"
      - "Combine generics and varargs judiciously"
      - "Consider typesafe heterogeneous containers"

  chapter_6:
    title: "Enums and Annotations"
    items:
      - "Use enums instead of int constants"
      - "Use instance fields instead of ordinals"
      - "Use EnumSet instead of bit fields"
      - "Use EnumMap instead of ordinal indexing"
      - "Emulate extensible enums with interfaces"
      - "Prefer annotations to naming patterns"
      - "Consistently use the Override annotation"
      - "Use marker interfaces to define types"

  chapter_7:
    title: "Lambdas and Streams"
    items:
      -

...(完整内容在原仓库)...

数据来源

联系方式

有问题或建议,在本 skill 下留言。

FAQ

这个 skill 是干什么的?

把 `java-general-purpose-cursorrules-prompt-file.mdc` 这条 Cursor 编码规则打包成可调用的 AI skill,帮你把代码生成统一到一致的标准上。

> Cursor rules for Java General Purpose.

👤 用户需要做什么?
  • [ ] 知道这条规则适合用在什么场景(参考下面"适用场景")
  • [ ] 把规则原文内容应用到 IDE 项目的 `.cursor/rules/` 目录(直接复制 .mdc 文件)
  • [ ] 调本 skill 时说清楚你的代码任务(语言/框架/目标)
  • [ ] 输出后人工 review 风格是否符合预期