예제 #1
0
  @Test
  public void defaultMethod() throws Exception {
    Formula formula =
        new Formula() {
          @Override
          public double calculate(int a) {
            return sqrt(a * 100);
          }
        };

    assert formula.calculate(100) == 100.0;
    assert formula.sqrt(16) == 4.0;
  }
예제 #2
0
  public static void main(String[] args) {
    Formula formula1 =
        new Formula() {
          @Override
          public double calculate(int a) {
            return sqrt(a * 100);
          }
        };

    formula1.calculate(100); // 100.0
    formula1.sqrt(-23); // 0.0
    Formula.positive(-4); // 0.0

    //        Formula formula2 = (a) -> sqrt( a * 100);
  }