
- Apex 程式設計教程
- Apex - 主頁
- Apex - 概述
- Apex - 環境
- Apex - 示例
- Apex - 資料型別
- Apex - 變數
- Apex - 字串
- Apex - 陣列
- Apex - 常量
- Apex - 決策制定
- Apex - 迴圈
- Apex - 集合
- Apex - 類
- Apex - 方法
- Apex - 物件
- Apex - 介面
- Apex - DML
- Apex - 資料庫方法
- Apex - SOSL
- Apex - SOQL
- Apex - 安全
- Apex - 呼叫
- Apex - 觸發器
- Apex - 觸發器設計模式
- Apex - 管理者限制
- Apex - 批處理
- Apex - 除錯
- Apex - 測試
- Apex - 部署
- Apex 有用資源
- Apex - 快速指南
- Apex - 資源
- Apex - 討論
Apex - 常量
如在其他任何程式語言一樣,常量是指宣告或賦值後其值不會改變的變數。
在 Apex 中,常量用於定義在整個程式執行期間應具有常量值的變數。Apex 常量使用關鍵字“final”宣告。
示例
考慮一個 CustomerOperationClass 類和其中的常量變數 regularCustomerDiscount −
public class CustomerOperationClass { static final Double regularCustomerDiscount = 0.1; static Double finalPrice = 0; public static Double provideDiscount (Integer price) { //calculate the discount finalPrice = price - price * regularCustomerDiscount; return finalPrice; } }
要檢視上述類的輸出,您必須在“開發人員控制檯匿名視窗”中執行以下程式碼 −
Double finalPrice = CustomerOperationClass.provideDiscount(100); System.debug('finalPrice '+finalPrice);
廣告