FragmentからActivityのメソッドを呼び出したい(コールバックしたい)こと、ありますよね。 二昔前には幾度か議論になりましたが、概ね以下のような内容だったかと思います。 Y.A.M の 雑記帳: Fragment から Activity にコールバックする方法 当時、私の中で(面倒くさいながらも)有力だったのは、「インターフェースを被せることで特定のActivityへの依存性を排除しつつ、基本的には getActivity() で逐一取ってきて、キャストの成否をちゃんとチェックする」という方針でした。 今回ご紹介するものも方針はまったく同じなのですが、Java8のOptionalと高階関数を使うと少しスッキリ書けるよ、というお話です。 コード public class HogeFragment extends Fragment { // 略 private void onCli