I came across an interesting quirk when defining custom properties within a custom control — there are some names that cannot be used.
While working on a reusable control for charting functionality, I wanted to add a custom property called chartTheme. As I started to type the name, it let me type ‘cha’, then prevented the ‘r’ from working. I initially thought something was wrong with the key on my keyboard, because it let me type other characters. After fiddling with it for a moment, I realized that it just refused to allow the property to be named ‘char’.
To work around it, I typed the ‘t’ next and then added the ‘r’ afterwards. (After the word ‘chart’ was in the field, it would not let me delete the ‘t’, which would have changed the word back to ‘char’.)
I tried other data type names and found a similar issue. Then I tried other keywords (true, class, etc) and got the same result.
It looks like a limitation on reserved words in Java in general. (Logically, this makes sense because everything is compiled down to Java.)
I found tested these reserved words and tested them all and verified that they are cannot be used:
- abstract
- assert
- boolean
- break
- byte
- case
- catch
- char
- class
- const
- continue
- default
- double
- do
- else
- enum
- extends
- false
- final
- finally
- float
- for
- goto
- if
- implements
- import
- instanceof
- int
- interface
- long
- native
- new
- null
- package
- private
- protected
- public
- return
- short
- static
- strictfp
- super
- switch
- synchronized
- this
- throw
- throws
- transient
- true
- try
- void
- volatile
- while
I also noticed that ‘con’ and ‘nul’ are not allowed.
This can be annoying when typing a property name, but it’s easily worked around by adding a different character and then fixing it.
I’m curious to hear if you’ve had similar experience.
1. Are there any other words that you’ve come across?
2. Are there other places where you’ve seen this limitation?
