--- id: java-this-keyword title: "Java This Keyword" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["this keyword", "μžλ°” this"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.9 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["java", "programming", "w3schools", "oop", "this"] raw_sources: ["https://www.w3schools.com/java/java_this.asp"] applied_in: [] github_commit: "" --- # [[Java This Keyword]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Without `this`, writing `x = x;` inside a constructor whose parameter shadows the class field would silently assign the parameter to itself, leaving the actual class variable uninitialized at 0 β€” `this.x = x;` is the only way to disambiguate which `x` is meant when names collide. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`this`** β€” refers to the current object inside a method or constructor. [S1] - **Name-shadowing scenario** β€” when a parameter has the same name as a class attribute, the parameter temporarily hides the class variable within that scope. [S1] - **`this.x = x;`** β€” assigns the parameter's value to the class attribute, resolving the shadow. [S1] - **`this(...)`** β€” calls another constructor in the same class; must be the FIRST statement in the calling constructor. [S1] - **Constructor chaining use case** β€” providing default values or reusing initialization code instead of repeating it. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Shadow resolution: `public Main(int x) { this.x = x; }` β€” without `this`, `x = x;` would leave the class variable at its default 0. [S1] - Constructor chaining: `public Main(String modelName) { this(2020, modelName); } public Main(int modelYear, String modelName) { this.modelYear = modelYear; this.modelName = modelName; }` β€” calling `new Main("Corvette")` yields `2020 Corvette` via the default-year chain. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **this() 호좜 μœ„μΉ˜ μ œμ•½**: μƒμ„±μž λ‚΄μ—μ„œ this()λ₯Ό ν˜ΈμΆœν•  경우 λ°˜λ“œμ‹œ 첫 번째 λ¬Έμž₯이어야 ν•œλ‹€λŠ” 점이 λͺ…μ‹œλ¨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” κΈ°λ³Έκ°’(2020λ…„ν˜•)을 μ œκ³΅ν•˜λŠ” μƒμ„±μž 체이닝은 μ΄ˆκΈ°ν™” μ½”λ“œ 쀑볡을 ν”Όν•˜λŠ” ν‘œμ€€ νŒ¨ν„΄μ΄λ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Constructor chaining with this() for default values (Java): ```java public class Main { int modelYear; String modelName; public Main(String modelName) { this(2020, modelName); // must be first statement } public Main(int modelYear, String modelName) { this.modelYear = modelYear; this.modelName = modelName; } } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.90 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[Java Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[Java Constructors]], [[Java Modifiers]] - **μ°Έμ‘° λ§₯락:** 이름 좩돌 ν•΄μ†Œ 및 μƒμ„±μž 체이닝 β€” Modifiers μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” Java this β€” https://www.w3schools.com/java/java_this.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "Java this Keyword" page (Astra wiki-curation, P-Reinforce v3.1 format).