A|A Method can has the same name of the class
【A|A Method can has the same name of the class】构造方法必须与类同名,方法也可以与类同名。
My guess is that it's allowed because explicitly disallowing it would add another requirement to Java's identifier naming rules for very little benefit. Unlike, say, C++, Java always requires that constructors are called with the new keyword, so there's never any ambiguity about whether an identifier refers to a method or a constructor. I do agree that a method with the same name as its parent class is quite confusing at first glance, and it should be almost certainly be avoided. That said, I'm glad they chose not to further complicate the language by banning such methods.
推荐阅读
- canvas(一)基本用法
- cannot|cannot be read or is not a valid ZIP file
- vue|vue canvas 手绘进度条动画
- Mockito|Mockito mock void methods Example
- HashMap&ConcurrentHashMap&HashTable
- canvas不过如此(一)
- 运行报错Cannot|运行报错Cannot find module '@babel/compat-data/corejs3-shipped-proposals’
- HTML|HTML canvas中translate()与rotate()的理解
- (4)Canal多实例使用
- HashMap负载因子