Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

380
Visualizações
What does ()->{} represent in java?

What does ()->{} represent in java?. Any help would be highly appreciated.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

It's a lambda expression, basically a concise way of writing a function. ()->{} is a function that takes no arguments and does nothing. A longer way of writing the same thing:

new Runnable() {
    @Override
    public void run() {
        // nothing
    }
};
over 4 years ago · Santiago Trujillo Relatório

0

Let's consider old way of writing functions(i.e methods) in java.

//lets assume this is inside calculate class
public int sum(int a, int b){
     return a+b;
}

in java 8 we have something called lambda's in which we have concept called passing behaviours(methods) to another behaviour(methods).

in those case we use syntax like (a,b) -> return a+b;

BiFunction<Integer,Integer,Integer> sum= (a,b)->{
            return a+b;
        };

System.out.println(sum.apply(1, 2));

Even we can store Function in a variable and pass to another function. you can see here

now lets see about syntax (a,b) ->{ return a + b}; (a,b) are arguments to function;

and the line of code inside {} represent the behaviour. -> is to separate both left and right expressions.

you can explore more about java8 and lambda over here

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda