Loading topic
sort by wrapping one method inside an anonymous class. That worked because Comparator is a special kind of interface. This chapter explains what makes it special.2 min reads -> s.length() does not name its own type. It does not say "I am a Function" or "I am a Comparator". The compiler still has to give every lambda a type, and it works that type out from the code around the lambda. This chapter shows how.2 min readjava.util.function. A package is a named group of related classes a2 min reads -> s.toUpperCase() just passes s to toUpperCase. Java gives you a shorter way to write this, called a method reference.2 min readjava.util.function package has many ready-made interfaces. Sometimes none of them fits your task well. When that happens, you can write your own functional interface. This chapter shows you how.2 min readList and Map types have methods that take a lambda as an argument. These methods let you replace short loops with one clear line.2 min readx -> x * 2 or s -> s.isEmpty(). Real programs often need bigger behavior, like "double a number, then add three" or "keep words that are not empty and are short." You could write one large lambda for each case. A cleaner way is to compose s2 min readthis refers to in each, and which variable names you are allowed to reuse.2 min readFunction<T, R> and Predicate<T>, use generics. Generics only work with object types like Integer. They do not work with primitive types like int. This chapter shows what that limit costs and which interfaces avoid it.2 min readremoveIf and replaceAll. Those methods change the list itself. Streams give you a different way to work with a collection. You describe a series of steps, and Java runs your lambdas on each element as it passes through those steps.2 min read==.2 min read