Apex-constants
提供:Dev Guides
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);