Home > Java > javaTutorial > body text

How to implement lambda expression in JShell in Java 9?

WBOY
Release: 2023-08-20 18:29:02
forward
1466 people have browsed it

如何在Java 9的JShell中实现lambda表达式?

JShell 是Java的第一个REPL 命令行工具,提供对Java编程语言元素的交互使用。我们可以使用这个工具在类的隔离环境中测试功能。 JShell 命令行中创建了一个简单而易用的编程环境,它接收用户的输入,读取并打印结果。 lambda表达式是一种不属于任何类的创建的函数。

在下面的示例中,我们可以在JShell中实现一个lambda表达式。

<strong>C:\Users\User>jshell
| Welcome to JShell -- Version 9.0.4
| For an introduction type: /help intro

jshell> Consumer<String> s = (String s) -> System.out.println(s)
s ==> $Lambda$14/1268066861@3159c4b8</strong>
Copy after login

如果我们记不住Consumer 接口的方法,那么输入一个已创建的变量的名称,然后加上并按下Tab键。它会显示可以在Consumer 接口上调用的方法列表。

<strong>jshell> s.
accept( andThen( equals( getClass() hashCode()
notify() notifyAll() toString() wait(

jshell> s.accept("Welcome to Tutorialspoint")
Welcome to Tutorialspoint</strong>
Copy after login

The above is the detailed content of How to implement lambda expression in JShell in Java 9?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template