中文字幕一区二区人妻电影,亚洲av无码一区二区乱子伦as ,亚洲精品无码永久在线观看,亚洲成aⅴ人片久青草影院按摩,亚洲黑人巨大videos

Java 9 REPL (JShell)

Java 9 新特性 Java 9 新特性

REPL(Read Eval Print Loop)意為交互式的編程環(huán)境。

JShell 是 Java 9 新增的一個交互式的編程環(huán)境工具。它允許你無需使用類或者方法包裝來執(zhí)行 Java 語句。它與 Python 的解釋器類似,可以直接 輸入表達式并查看其執(zhí)行結果。

執(zhí)行 JSHELL

$ jshell
|  Welcome to JShell -- Version 9-ea
|  For an introduction type: /help intro
jshell>

查看 JShell 命令

輸入 /help 可以查看 JShell相關的命令:

jshell> /help
|  Type a Java language expression, statement, or declaration.
|  Or type one of the following commands:
|  /list [<name or id>|-all|-start]
|  list the source you have typed
|  /edit <name or id>
|  edit a source entry referenced by name or id
|  /drop <name or id>
|  delete a source entry referenced by name or id
|  /save [-all|-history|-start] <file>
|  Save snippet source to a file.
|  /open <file>
|  open a file as source input
|  /vars [<name or id>|-all|-start]
|  list the declared variables and their values
|  /methods [<name or id>|-all|-start]
|  list the declared methods and their signatures
|  /types [<name or id>|-all|-start]
|  list the declared types
|  /imports 
|  list the imported items

執(zhí)行 JShell 命令

/imports 命令用于查看已導入的包:

jshell> /imports
|    import java.io.*
|    import java.math.*
|    import java.net.*
|    import java.nio.file.*
|    import java.util.*
|    import java.util.concurrent.*
|    import java.util.function.*
|    import java.util.prefs.*
|    import java.util.regex.*
|    import java.util.stream.*
jshell>

JShell 執(zhí)行計算

以下實例執(zhí)行 JShell 簡單計算:

jshell> 3+1
$1 ==> 4
jshell> 13%7
$2 ==> 6
jshell> $2
$2 ==> 6
jshell>

JShell 創(chuàng)建與使用函數(shù)

創(chuàng)建一個函數(shù) doubled() ,將傳入的整型參數(shù)乘于 2 后返回:

jshell> int doubled(int i){ return i*2;}
|  created method doubled(int)
jshell> doubled(6)
$3 ==> 12
jshell>

退出 JShell

輸入 /exit 命令退出 jshell:

jshell> /exit
| Goodbye 

Java 9 新特性 Java 9 新特性

其他擴展