getServletContext().setAttribute("count", 0);
// 步驟 1: 調用 getServletContext() → 返回 ServletContext 實例
// 步驟 2: 在該實例上調用 setAttribute(...)
這是標準的方法鏈/鏈式調用,核心規則:方法返回對象引用,隨後可繼續調用該對象的方法。
ServletContext ctx = getServletContext(); // 獲取對象
ctx.setAttribute("count", 0); // 對對象操作
new StringBuilder().append("a").append("b").toString()list.stream().filter(...).map(...).collect(...)document.getElementById("id").style.color = "red"this 實現自身鏈式,適用於構建器、配置類。