书上写的java关键字里有goto,但从网上一看说goto是java的保留关键字,碰巧昨天笔试遇到了此类笔试,让从选项中选出java的关键字,选项中有goto,选还是不选?应该怎么确认是不是关键字?请大神指教。java

解决方案 »

  1.   

    goto 是保留字
    不能够使用
      

  2.   

    刚刚google了一下   “java  keyword reserved word”找到了这么一段话:
    There are some words that you cannot use as object or variable names in a Java program. These words are known as “reserved” words; they are keywords that are already used by the syntax of the Java programming language.我的理解是java预留了一部分名称不能为用户给变量或对象命名,叫保留字(reserved word),其中已近被java使用了的保留字就是关键字(keyword), 所以 严格来讲 goto是保留字,目前还不是关键字~~
    给个链接:http://java.about.com/od/javasyntax/a/reservedwords.htm
      

  3.   

     The keywords const and goto are reserved, even though they are not currently used. true, false, and null might seem like keywords, but they are actually literals; you cannot use them as identifiers in your programs.来自oracle. http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html
      

  4.   

    The keywords goto and const are C++ keywords reserved, but not currently used, in Java.
    This enables Java compilers to identify them and to produce better error messages if they
    appear in Java programs.
    The literal values true, false, and null are not keywords, just like literal value 100.
    However, you cannot use them as identifiers, just as you cannot use 100 as an identifier. In the
    code listing, we use the keyword color for true, false, and null to be consistent with their
    coloring in Java IDEs.
    assert is a keyword added in JDK 1.4 and enum is a keyword added in JDK 1.5.
      

  5.   

    总之 你不能使用goto作为变量名。
    比如
    public class Test{
    public static void main(String args[]){
    int main = 5;
    //int goto = 10;
    System.out.println(main);
    //System.out.println(goto);
    }
    }
    一般称呼其为保留字,应该不算关键字。如果题目里面没得其它关键字选就选这个吧,多选的话,就不要选了。
      

  6.   

    goto是保留下来的关键字,但是一直没有被使用。
      

  7.   

    goto应该算保留字吧。也许未来就成真正的关键字了。
      

  8.   

    Java语言中goto是保留关键字,没有goto语句,也没有任何使用goto关键字的地方。
     
    Java中也可在特定情况下,通过特定的手段,来实现goto的功能。显然Java不愿意开发者随意跳转程序。下面解释两个特定:
    特定情况:只有在循环体内,比如for、while语句(含do...while语句)中。
    特定手段:语句标签和循环控制关键字break、continue,语法格式是:break/continue 语句标签。
    我所见的程序段里面没见过goto,但是当时学习的时候老师说所有要用标签的内容都有其它解决办法替代,所以对于标签老师就这么一句给我们跳过了我所见过的程序段里面就这么一个是用标签的:// 设置语法高亮
    public void setHighLight(StyledDocument doc, String token, int start, int length)
    {
    // 保存需要对当前单词对应的外观属性
    SimpleAttributeSet currentAttributeSet = null; outer: for (SimpleAttributeSet att : attMap.keySet())
    {
    // 取出当前颜色对应的所有关键字
    ArrayList keywords = attMap.get(att);
    // 遍历所有关键字
    for (Object keyword : keywords)
    {
    // 如果该关键字与当前单词相同
    if (keyword.toString().equals(token))
    {
    // 跳出循环,并设置当前单词对应的外观属性
    currentAttributeSet = att;
    break outer;
    }
    }
    } // 如果当前单词对应的外观属性不为空
    if (currentAttributeSet != null)
    {
    // 设置当前单词的颜色
    doc.setCharacterAttributes(start, length, currentAttributeSet, false);
    }
    else
    {// 否则使用普通外观来设置该单词
    doc.setCharacterAttributes(start, length, normalAttr, false);
    }
    }
    但是这个段落完全可以用一个递归实现的。
      

  9.   

    这个是JAVA的保留字,意思是在以后的版本中有可能会以关键字的形式出现,因此和关键字是一个效果,都不能作为变量名称等使用
      

  10.   

    看过一本有关面试题书的介绍,说goto是保留字,而不是关键字
      

  11.   

    goto是保留字,目前没有作用它,goto原本是C语言中的
      

  12.   

    是保留字  不是关键字,不知道留着goto想干什么 难道想学c语言那样无条件跳转
      

  13.   

    摘自《Java基础入门教程.pdf》
      

  14.   

    应该是看题目的选项的有别的选项应该是选别的。。如果没有别的选项goto应该也是可以选的吧