Java 8 has many features. One of most important feature is First class Function
The core idea of the concept is use the function as Parameter in any other function
below code explains the First class function concept;
//---------------------------------
File[] fil_dir=new File("d:").listFiles(new FileFilter() {
@Override
public boolean accept(File file{
file.isHidden();
}
});
System.out.println(fil_dir.length);
the above program is used to find the hidden files in directory. Here we applying the filter class which is Anonymous Inner class . The above code can be re-written as below using first class function concept
//------------------------------------
File[] fil_dir=new File("d:").listFiles(File::isHidden());
System.out.println(fil_dir.length);
File::isHidden() - this code acts as first class function in listFiles method.
The syntax for applying first class function in java is ClassName :: MethodName
The core idea of the concept is use the function as Parameter in any other function
below code explains the First class function concept;
//---------------------------------
File[] fil_dir=new File("d:").listFiles(new FileFilter() {
@Override
public boolean accept(File file{
file.isHidden();
}
});
System.out.println(fil_dir.length);
the above program is used to find the hidden files in directory. Here we applying the filter class which is Anonymous Inner class . The above code can be re-written as below using first class function concept
//------------------------------------
File[] fil_dir=new File("d:").listFiles(File::isHidden());
System.out.println(fil_dir.length);
File::isHidden() - this code acts as first class function in listFiles method.
The syntax for applying first class function in java is ClassName :: MethodName