Apex - 常量
由 kaikai0220 创建,youj 最后一次修改 2016-12-12 与任何其他编程语言一样,常量是一旦声明或赋值就不改变它们的值的变量。在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; }}要查看上述类的Output,您必须在开发人员控制台匿名窗口中执行以下代码: Double finalPrice = CustomerOperationClass.provideDiscount(100);System.debug('finalPrice '+finalPrice);
Apex - 常量