<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ## 1.1 行為參數化的實現原理 > 以下程序的目的是對Model類型的列表進行多種方式的**過濾**,將滿足條件的元素篩選出來。 ### 1.1.1 Model類 ```java public class Model { private int height; private String color; public int getHeight() { return height; } public void setHeight(int height) { this.height = height; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } } ``` ### 1.1.2 接口以及兩種實現 ```java public interface Test { boolean test(Model model); } ``` ```java public class ColorTest implements Test{ @Override public boolean test(Model model) { return "red".equals(model.getColor()); } } ``` ```java public class HeightTest implements Test{ @Override public boolean test(Model model) { return model.getHeight() > 10; } } ``` ### 1.1.3 測試中的行為參數化 類似 `策略模式`,以下是行為參數化的測試程序: ```java import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) { List<Model> modelList = new ArrayList<>(); List<Model> heightList = filter(modelList,new ColorTest()); List<Model> colorList = filter(modelList, new HeightTest()); } static List<Model> filter(List<Model> appleList, Test test) { List<Model> result = new ArrayList<>(); for (Model model : appleList) { if (test.test(model)) { result.add(model); } } return result; } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看