Java 8 Method References explained in 5 minutes

Discussions

News: Java 8 Method References explained in 5 minutes

  1. Java 8 Method References explained in 5 minutes (1 messages)

    Previously we have looked at Lambda Expression, Streams API and Default Methods. In this latest article in the series, we will be looking at Method References.

    What is Method References?

    It is a feature which is related to Lambda Expression. It allows us to reference constructors or methods without executing them. Method references and Lambda are similar in that they both require a target type that consist of a compatible functional interface.

    Types of Functional Interface

    There are four types of method reference, this is summarized below.

    Type Example Syntax

    1. Reference to a static method - Example: ContainingClass::staticMethodName Syntax: Class::staticMethodName
    2. Reference to a constructor - Example: ClassName::new Syntax: ClassName::new
    3. Reference to an instance method of an arbitrary object of a particular type - Example: ContainingType::methodName Syntax: Class::instanceMethodName
    4. Reference to an instance method of a particular object - Example: containingObject::instanceMethodName Syntax:object::instanceMethodName

    I will explain further about the four types of method referenced in the table.

    (Read the rest...)

    Threaded Messages (1)

  2. broken url[ Go to top ]

    Red the rest link doesnt work