Home java What does it mean "- & gt;" in java?

What does it mean “- & gt;” in java?




I study This tutorial . In some screenshots, there is a - & gt; , for example:

vertx.deployverticle ("com.mycompany.myrderprocessortellic", res - & gt; {
 if (res.Succeeded ()) {
  System.Out.printLN ("Deployment ID IS:" + Res.Result ());
 } else {
  System.Out.printLN ("Deployment Failed!");

did not come across before with such. Tell me, please, what is it and where you can read good materials about it.

Answer 1, Authority 100%

This is a lambda expression – an anonymous function. Simply put, this is the method without an ad (without access modifiers that return value and name) .

appeared in the 8 version of Java.

Example of use

Write a simple example function interface :

Public Interface Lambda {
  // Interface Method with Missing Implementation
  int getDoubleValue (int val);
  // Interface Method with default implementation
  Default Void Printval (Int Val) {
    System.out.printLN (VAL);

The function interface must have only one abstract method. You can read about the reasons for such a limitation here .

Now create a class for use

Public Class ClassForlambda {
  Public Static Void Main (String [] Args) {
    // declare a link to the function interface
    Lambda lam;
    // Parameter for our abstract method
    int num = 9;
    // prescribate the first implementation option
    LAM = (VAL) - & gt; Val * 2;
    System.out.PrintLN (LAM.GETDOUBLEVALUE (NUM));
    // We prescribe a second embodiment
    LAM = (VAL) - & gt; {
      System.Out.printLN ("Your Number IS" + Val);
      Return Val * 2;
    System.out.PrintLN (LAM.GETDOUBLEVALUE (NUM));

As you can see, the appeal to the method has not changed. Only implementation was subjected to change.


Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions