Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Post Timeline

Active reading. Used more standard formatting. Dressed the naked link. Removed unnecessary formatting.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 110
  • 134

:: is called Method Referencea method reference. It is basically a reference to a single method. iI.e., it refers to an existing method by name.

Short Explanation:
Below

Below is an example of a reference to a static method:

E.g., instead of writing the lambda body

The only major criterion to satisfy is: the method you provide should have a similar signature to the method of the functional interface you use as object referencethe method you provide should have a similar signature to the method of the functional interface you use as object reference.

square expects an argument and returns a double. The get method in Supplier returns a value, but it does not take an argument. Thus, this results in an error.

A method reference refers to the method of a functional interface. A method reference refers to the method of a functional interface. (As mentioned, functional interfaces can have only one method each).)

Some more examples: the accept method in Consumer takes an input, but it doesn't return anything.

Above, getRandom takes nodoesn't take any argument and returns a double. So any functional interface that satisfies the criteria of: take no argument and return take no argument and return doubledouble can be used.

For further reference, see http://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-final.html State of the Lambda .

:: is called Method Reference. It is basically a reference to a single method. i.e. it refers to an existing method by name.

Short Explanation:
Below is an example of a reference to a static method:

E.g. instead of writing the lambda body

The only major criterion to satisfy is: the method you provide should have a similar signature to the method of the functional interface you use as object reference.

square expects an argument and returns a double. The get method in Supplier returns a value but does not take an argument. Thus, this results in an error.

A method reference refers to the method of a functional interface. (As mentioned, functional interfaces can have only one method each).

Some more examples: the accept method in Consumer takes an input but doesn't return anything.

Above, getRandom takes no argument and returns a double. So any functional interface that satisfies the criteria of: take no argument and return double can be used.

For further reference, see http://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-final.html.

:: is called a method reference. It is basically a reference to a single method. I.e., it refers to an existing method by name.

Short Explanation:

Below is an example of a reference to a static method:

E.g., instead of writing the lambda body

The only major criterion to satisfy is: the method you provide should have a similar signature to the method of the functional interface you use as object reference.

square expects an argument and returns a double. The get method in Supplier returns a value, but it does not take an argument. Thus, this results in an error.

A method reference refers to the method of a functional interface. (As mentioned, functional interfaces can have only one method each.)

Some more examples: the accept method in Consumer takes an input, but it doesn't return anything.

Above, getRandom doesn't take any argument and returns a double. So any functional interface that satisfies the criteria of: take no argument and return double can be used.

For further reference, see State of the Lambda .

Bounty Awarded with 200 reputation awarded by Naman
edited body
Source Link
Naman
  • 32.8k
  • 32
  • 240
  • 385

:: is called Method Reference. It is basically a reference to a single method. Ii.e. it refers to an existing method by name.

:: is called Method Reference. It is basically a reference to a single method. I.e. it refers to an existing method by name.

:: is called Method Reference. It is basically a reference to a single method. i.e. it refers to an existing method by name.

Changed description of get method (see Supplier docs)
Source Link

square expects an argument and returns a double. The get method in Supplier expectsreturns a value but does not take an argument but doesn't return anything. Thus, this results in an error.

square expects an argument and returns a double. The get method in Supplier expects an argument but doesn't return anything. Thus, this results in an error.

square expects an argument and returns a double. The get method in Supplier returns a value but does not take an argument. Thus, this results in an error.

replaced a handful of terms where the words' actual definitions unambiguously didn't match the author's intent; fixed up grammar; a little formatting
Source Link
Loading
added 7 characters in body
Source Link
Jared Burrows
  • 55.9k
  • 26
  • 160
  • 190
Loading
don't paraphrase the quote from B. Goetz but include it as-is, make the source explicit [as a byproduct this gets rid of the "lambda's" grammar error]
Source Link
kryger
  • 13.2k
  • 8
  • 47
  • 68
Loading
edited body
Source Link
Mike
  • 14.8k
  • 32
  • 122
  • 184
Loading
formatting & spelling
Source Link
Mike
  • 14.8k
  • 32
  • 122
  • 184
Loading
added 45 characters in body
Source Link
Jatin
  • 31.8k
  • 16
  • 102
  • 173
Loading
deleted 57 characters in body
Source Link
Jatin
  • 31.8k
  • 16
  • 102
  • 173
Loading
added 212 characters in body
Source Link
Jatin
  • 31.8k
  • 16
  • 102
  • 173
Loading
added 212 characters in body
Source Link
Jatin
  • 31.8k
  • 16
  • 102
  • 173
Loading
added 452 characters in body
Source Link
Jatin
  • 31.8k
  • 16
  • 102
  • 173
Loading
deleted 1 character in body
Source Link
Jatin
  • 31.8k
  • 16
  • 102
  • 173
Loading
added 12 characters in body
Source Link
John Kugelman
  • 364.7k
  • 70
  • 555
  • 600
Loading
Fixed the link for Function interface and put the reference to applied method
Source Link
Loading
deleted 32 characters in body
Source Link
Jatin
  • 31.8k
  • 16
  • 102
  • 173
Loading
added 23 characters in body
Source Link
Jatin
  • 31.8k
  • 16
  • 102
  • 173
Loading
added 436 characters in body
Source Link
Jatin
  • 31.8k
  • 16
  • 102
  • 173
Loading
added 436 characters in body
Source Link
Jatin
  • 31.8k
  • 16
  • 102
  • 173
Loading
Source Link
Jatin
  • 31.8k
  • 16
  • 102
  • 173
Loading
lang-java

AltStyle によって変換されたページ (->オリジナル) /