Java Functional Interface

Java functional interface

  • A functional interface is simply an interface that has exactly one abstract method.
  • A functional interface is to be used by Lambda Expression.
  • The following types of members in an interface do NOT count for defining a functional interface:
    • Default methods.
    • Static methods.
    • Public methods inherited from the Object class.
    • Constants.
    @FunctionalInterface // This is not required 
    public interface Percentage { 
      static final double MAX = 100, MIN = 0; // It is allowed to have  constants
      public double getPercentage(double amounts, double value);  // the abstract method
      // It is allowed to override methods in Object class 
     @Override
      public boolean equals(Object obj);  
      default public double getMaxAdjusted() { // It is allowed to have default methods
        return MAX - 10;
      }
      static public double getMinPercentage() { // It is allowed to have static methods
        return MIN + 10;
      }
    }
    
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.