「Java」クラスにConsumerインターフェースを実装するサンプル
環境
JavaSE1.8
Eclipse 2019
書式
@FunctionalInterface
public interface Consumer<T>
単一の入力引数を受け取って結果を返さないオペレーションを表します。
accept(T t)
指定された引数でこのオペレーションを実行します。
使用例
package com.arkgame.study;
import java.util.function.Consumer;
public class ConsumerDemo {
      
      static Integer tt = 123;
      
      public static void main(String[] args) {
            Cft kk = new Cft();
            // acceptメソッド  指定された引数でこのオペレーションを実行
            kk.accept(tt);
            ;
      }
}
// Consumerインターフェースを実装
class Cft implements Consumer<Integer> {
      @Override
      public void accept(Integer tt) {
            Integer result = tt + 77;
            System.out.println(result);
      }
}
実行結果
200