Guava Library Introduction

Source: Internet
Author: User
Tags google guava

First, what is guava

1) Guava Library is a common tool library for many Java projects
2) The Guava Tool Library contains: set collection, concurrency concurrency, primitive Primitive, reflection reflection, comparison comparison, I/O operations, hash hashes, network networking, strings string, math functions math, cache caching, in-memory publish/subscribe ... and various levels of data types
3) requires JDK version 6 or higher

Second, the function interface

Before we dive into the guava library, we understand its function interfaces and understand these function interfaces to help us better master the Guava library.

Function Interface:

1) function interface is an interface that defines a single method
2) function interfaces contain well-known individual abstract methods (Sam,single abstract method)
3) The function interface provides the basis for a Java 8 lambda expression
The function interface is cool: you specify either interface as a method parameter, or you can pass a lambda expression in Java 8
4) function interface can be used as callback object

Third, some examples of function interfaces

The following example is a function interface for Java 8.

1. Function interface with single method parameters

@FunctionalInterface{    publicbooleancheck(Order o);}

Then we can create a lambda expression, using the function interface above.

IOrder newOrder = (Order o) -> o.getStatus().equals("NEW");

Or

IOrder newOrder = (o) ->o.getStatus().equals("NEW");
Description

1) The right side of the expression is a simple way to check the contents of a method-checking the state passed to the order object.
2) The power of a lambda expression can be manifested when a large number of lambda expressions are created that express demand behavior or functionality.

2, for example, immediately after the above example, to find large orders.

// Lambda表达式找出大额订单10000000;
// Lambda表达式找出新的大额订单ITrade issuerBigNewTradeLambda = (o) -> {    return o.getIssuer().equals("Honda") &&        10000000 &&        o.getStatus().equals("NEW");}
Iv. Summary

The Google Guava Library provides several useful Sam in "Com.google.common.base", including:
1) Function
Specifies a method that receives an instance of type "T" and returns an instance of type "R"
2) predicate
Specifies a method that passes a "T" type instance and returns a Boolean type
3) Supplier
Specifies a method that can return a value

It is also necessary to know that these Sam, though born in the guava library, have also joined Java 8.

Guava Library Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.