พารามิเตอร์เสถียรกับไม่เสถียร
ทำความเข้าใจสิ่งที่ทำให้ข้าม Composable ได้
พารามิเตอร์เสถียรกับไม่เสถียร เป็นบทเรียน Jetpack Compose Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Jetpack Compose Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
What Skipping Means
When a Composable re-runs but its inputs have not changed, Compose can skip it entirely. Skipping is how fast Compose apps stay fast. 🚀
Stability Decides Skipping
Compose only skips a Composable when every parameter is stable. One unstable input and the whole function re-executes on each recomposition.
What "Stable" Promises
A type is stable when Compose trusts that equals() is reliable and that public properties will not change without telling Compose.
Naturally Stable Types
Primitives, String, and function types are stable out of the box, so passing an Int or a lambda never blocks skipping.
fun Greeting(name: String, count: Int) {
Text("Hello $name x$count")
}val Properties Are Stable
A class with only val properties of stable types is itself stable. Immutable data is the friendliest input you can give Compose.
data class User(val id: Int, val name: String)var Makes a Type Unstable
A mutable var property can change behind Compose's back, so the class becomes unstable and its Composable can no longer skip.
data class Counter(var value: Int)Collections Look Unstable
Plain List, Map, and Set are treated as unstable, because the interface could hide a mutable ArrayList underneath.
fun ItemRow(items: List<String>) { }Why Interfaces Worry Compose
An interface parameter is unstable: the concrete implementation is unknown at compile time, so Compose cannot guarantee its equals() behaves.
Strong Skipping Mode
Newer Compose ships strong skipping, which lets unstable parameters compare by reference, so many cases skip without extra annotations.
Spotting Unstable Inputs
If a Composable redraws every frame for no visible reason, suspect an unstable parameter forcing a full re-run each time.
Stability Is About Trust
Stability is a promise to Compose, not magic. The more immutable your inputs are, the more work Compose is free to skip.
Quick Check
Test your grasp of stability.
Recap: Stable Wins
Compose skips a Composable only when every input is stable. Favor primitives, Strings, and val-only classes to keep redraws cheap. ✅
คำถามที่พบบ่อย
บทเรียน “พารามิเตอร์เสถียรกับไม่เสถียร” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “พารามิเตอร์เสถียรกับไม่เสถียร” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Jetpack Compose Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “พารามิเตอร์เสถียรกับไม่เสถียร”
ทำความเข้าใจสิ่งที่ทำให้ข้าม Composable ได้ คุณปฏิบัติ Jetpack Compose Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Jetpack Compose Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Jetpack Compose Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “พารามิเตอร์เสถียรกับไม่เสถียร” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Jetpack Compose Academy นี้ได้ไหม
ได้ บทเรียน Jetpack Compose Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- พารามิเตอร์เสถียรกับไม่เสถียร
- การข้าม @Stable และ @Immutable
- เลื่อนการอ่านสถานะออกไป
- ตัวตรวจสอบเลย์เอาต์และจำนวนการประกอบใหม่