Why do Java programmers like to name a variable “c

2019-01-13 04:02发布

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 ?

10条回答
姐就是有狂的资本
2楼-- · 2019-01-13 04:16

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.

查看更多
萌系小妹纸
3楼-- · 2019-01-13 04:22

Because they cannot use the word they want to use which is 'class'. It is reserved.

查看更多
戒情不戒烟
4楼-- · 2019-01-13 04:23

It's simply because 'class' is a reserved keyword, hence Class class isn't allowed. Therefore you'll see Class clazz or Class cls.

查看更多
等我变得足够好
5楼-- · 2019-01-13 04:23

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

查看更多
戒情不戒烟
6楼-- · 2019-01-13 04:26

Declaration Class clazz is popular in Java world, but it may be awkward for newcomers and spellcheckers. I've heard some people saying that it should be avoided according to principle of least astonishment.

As it is possible to say that a Class object represents a type, I personally prefer to declare such variables as Class type.

查看更多
唯我独甜
7楼-- · 2019-01-13 04:27

Simply put, class has class that clazz doesn't.

查看更多
登录 后发表回答