I've seen lots of codes have declaration like Class clazz
, where does this originate from ? Is this some kind of convention ? I think 'clazz' is not even an English word , has no meaning at all , how can so many programmers name a wrong name coincidentally ?
views:
348answers:
6Because they cannot use the word they want to use which is 'class'. It is reserved.
It's simply because 'class' is a reserved keyword, hence Class class
isn't allowed. Therefore you'll see Class clazz
or Class cls
.
It is just a English word replaced(Equavalent) by Keyword Class Keyword, to make people understand that it is a Class. and it is almost to increase the readability of the Code
Nothing big Logic involved in this
where does this originate from ?
I saw it first at Josh Bloch's puzzlers. But I'm pretty sure it was used much earlier by other developers. Josh Bloch just made it more famous.
clazz
has been used in Java in place of the reserved word "class" since JDK 1.0. "class" is what you want, but abbreviating or inserting junk ("a", "the", "_", etc) reduces clarity. clazz
just says class. "International" English speakers (those reading bother English and American) are used to transposing 's' and 'z'.
Since Java has had disclosed source and a suitable culture right from the start, worthwhile Java code and tutorials pick up the same conventions. That's one of the great things about the Java ecosystem, which I think has been an important part of its success.
Java does not have a feature that allows you to use a keyword as an identifier, unlike C# with its @
prefix (e.g. @class
is a valid identifier.)