Java 脚本标识符

Java脚本教程 – Java脚本标识符

标识符是脚本中变量,函数和标签的名称。

Nashorn中的标识符是一个Unicode字符序列,具有以下规则:

  • 可以包含字母,数字,下划线和美元符号
  • 不能以数字开头
  • 不能是保留字之一

例子

以下是有效标识符的示例:

Id
_id
e$Id
num1

以下是无效标识符:

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

关键词

Nashorn中保留字的列表用作关键字

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未来保留字的列表在严格模式

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;
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《Java 脚本标识符》
文章链接:https://zhuji.vsping.com/294132.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。