Java 9 的 JShell 中 Tab 鍵有何用途?


JShell 還可以提供一個自動補全功能,當我們透過按下Tab 鍵部分輸入現有的變數方法名稱時。如果無法從我們輸入的內容確定一個條目,那麼就會提供可能的選項。

在 JShell 中按下 Tab 鍵將執行以下一項任務

  • 如果沒有其他名稱與我們輸入的內容匹配,JShell 將為我們輸入名稱的其餘部分。
  • 如果有以相同字母開頭的多個名稱,那麼 JShell 將顯示這些名稱的列表以幫助我們輸入下一步,然後輸入下一個字母並再次按Tab 以完成輸入名稱。
  • 如果沒有名稱與我們到目前為止輸入的內容匹配,則會播放警報聲作為反饋。

示例

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

jshell> String studentName(String firstName, String lastName)
...> {
...>    return firstName + lastName;
...> }
| created method studentName(String, String)

jshell> /methods
| String studentName(String, String)

jshell> str <Press Tab Key>
studentName(

jshell> studentName(
studentName(

Signatures:
String studentName(String firstName, String lastName)

<press tab again to see documentation>

jshell> studentName(
String studentName(String firstName, String lastName)
<no documentation found>

<press tab again to see all possible completions; total possible completions: 545>

更新於: 2020 年 2 月 21 日

215 次瀏覽

開啟您的 職業生涯

完成課程,獲得認證

開始吧
廣告
© . All rights reserved.