It comes down to the actual compiler and its ability to distinguish what a token means within its context. However, in this particular case, it is the compiler's inability to distinguish what the token class
means in a different context. It is a hard and fast rule that class
, regardless of its context, is used to denote the declaration of a class, and as such it is a reserved word. That is as simple and as low-level as it gets.
If you feel compelled, you could write your own Java compiler to include a contextual rule that will allow you to use class
as a variable name. Though I think it would be far better use of your time to just use clazz
or klass
-- it would probably be good for your health as well.