Recall callbacks.

Passing Functions

public interface Comparator<T> {
	public abstract int compare(T o1, T o2);
}

public class StringCompare implements Comparator<String>{
	public int compare(String s1, String s2){
		return s1.length() - s2.length();
	}
}

String[] strarr = new ... ;
Arrays.sort(starr,StringCompare);

Functional Interfaces

<aside> 💡 Interfaces that define a single function are called Functional Interfaces.

</aside>

Examples: Comparator, Timerowner (in callback).


Lambda Expressions

<aside> 💡 Lambda expressions denote anonymous functions.

</aside>