简体   繁体   中英

Java Reserve Keywords

Are generic , cast , and threadsafe reserved keywords in java? I am aware of the 52 keywords in java but looking for the new reserved keyword list.

See this link here . It's the reserved keyword list for Java 6.


    abstract    continue  for           new            switch
    assert (c)  default   goto (a)      package        synchronized
    boolean     do        if            private        this
    break       double    implements    protected      throw
    byte        else      import        public         throws
    case        enum (d)  instanceof    return         transient
    catch       extends   int           short          try
    char        final     interface     static         void
    class       finally   long          strictfp (b)   volatile
    const (a)   float     native        super          while

    (a) not used
    (b) added in 1.2
    (c) added in 1.4
    (d) added in 5.0 

So, no, neither of those three words you listed are in the reserved set.

This keyword list can also be found in the Java language specification in section 3.9.

Java keywords are listed in the Java language spec :

    Keyword: one of
            abstract    continue    for           new          switch
            assert      default     if            package      synchronized
            boolean     do          goto          private      this
            break       double      implements    protected    throw
            byte        else        import        public       throws
            case        enum        instanceof    return       transient
            catch       extends     int           short        try
            char        final       interface     static       void 
            class       finally     long          strictfp     volatile
            const       float       native        super        while

The keywords const and goto are reserved, even though they are not currently used. This may allow a Java compiler to produce better error messages if these C++ keywords incorrectly appear in programs.

While true and false might appear to be keywords, they are technically Boolean literals. Similarly, while null might appear to be a keyword, it is technically the null literal.

According to Oracle documentation generic , cast , threadsafe are not reserved Java keywords.

Till date, There are only 50 keywords in java. Those are listed below

abstract        continue            for           new           switch
assert***       default         goto*             package   synchronized
boolean     do                  if            private   this
break       double          implements    protected throw
byte        else            import            public    throws
case        enum****            instanceof    return    transient
catch       extends         int           short         try
char        final           interface     static    void
class       finally         long              strictfp**    volatile
const*      float           native            super         while

*   not used
**  added in 1.2
*** added in 1.4
****    added in 5.0

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.

Please refer http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM