Home | History | Annotate | Download | only in java8
      1 // Copyright 2017 The Bazel Authors. All rights reserved.
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //    http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 package com.google.devtools.build.android.desugar.testdata.java8;
     15 
     16 /**
     17  * An interface that has a default method, and a non-empty static initializer. The initializer is
     18  * NOT expected to run during desugaring.
     19  */
     20 public interface FunctionalInterfaceWithInitializerAndDefaultMethods {
     21 
     22   ClassWithInitializer CONSTANT = new ClassWithInitializer();
     23   boolean BOOLEAN = getFalse();
     24   char CHAR = "hello".charAt(0);
     25   byte BYTE = Byte.parseByte("0");
     26   short SHORT = Short.parseShort("0");
     27   int INT = Integer.parseInt("0");
     28   float FLOAT = Float.parseFloat("0");
     29   long LONG = Long.parseLong("0");
     30   double DOUBLE = Double.parseDouble("0");
     31 
     32   int convert();
     33 
     34   /**
     35    * The default method ensures that the static initializer of this interface will be executed when
     36    * the interface is loaded.
     37    */
     38   default void defaultMethod() {}
     39 
     40   static boolean getFalse() {
     41     return false;
     42   }
     43 
     44   /**
     45    * A class with a static initializer that has side effects (In this class, the printing to stdout)
     46    */
     47   class ClassWithInitializer {
     48     static {
     49       System.out.println("THIS STRING IS NOT EXPECTED TO APPEAR IN THE OUTPUT OF DESUGAR!!!");
     50     }
     51 
     52     /**
     53      * A lambda to trigger Desugar to load the interface {@link
     54      * FunctionalInterfaceWithInitializerAndDefaultMethods}
     55      */
     56     public FunctionalInterfaceWithInitializerAndDefaultMethods length(String s) {
     57       return s::length;
     58     }
     59   }
     60 }
     61