Java 腳本標(biāo)識符

2018-03-18 14:24 更新

Java腳本教程 - Java腳本標(biāo)識符


標(biāo)識符是腳本中變量,函數(shù)和標(biāo)簽的名稱。

Nashorn中的標(biāo)識符是一個(gè)Unicode字符序列,具有以下規(guī)則:

  • 可以包含字母,數(shù)字,下劃線和美元符號
  • 不能以數(shù)字開頭
  • 不能是保留字之一

例子

以下是有效標(biāo)識符的示例:

Id
_id
e$Id
num1

以下是無效標(biāo)識符:

4num    //Cannot start with a digit
emp id  //Cannot contain spaces
emp+id  //Cannot contains the + sign
break   //break  is a reserved word and cannot be used as an identifier

關(guān)鍵詞

Nashorn中保留字的列表用作關(guān)鍵字

break         do           instanceof       typeof
case          else         new              var
catch         finally      return           void
continue      for          switch           while
debugger      function     this             with
default       if           throw
delete        in           try

Nashorn未來保留詞的列表

class       enum        extends     super
const       export      import

Nashorn未來保留字的列表在嚴(yán)格模式

implements      let           private      public
yield           interface     package      protected
static

注釋

Nashorn支持兩種類型的注釋:

  • 單行注釋
  • 多行注釋

在Nashorn中編寫注釋的語法與Java的語法相同。

以下是注釋的示例:

// A single-line comment
var Id;

/* 
   A multi-line comment
*/
var et;
var d;
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號