Apex-constants

提供:Dev Guides
2020年6月22日 (月) 19:30時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

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);