开发者

How can I recognize whether it is a class or interface in java by seeing the name?

I like to know how can I recognize whether it is a class or interface by seeing the name .. For example all class name starts with capital letters.. method name starts with small name.. 开发者_运维技巧Is there any specific way to recognize it?

Thanks


Some people make all their interfaces start with an I. Like IPopup, or IController. I personally hate this.

I was taught that an interface should be an adjective, a class should be a noun. For example: Class: Controller, Interface: Controllable


You cannot. Some people use a naming convention that distinguishes, but many people do not. For example, Sun does not.


The Java language makes no specific requirements on naming conventions. Indeed, you can define a method CamelCase() or a class lowercase. There are some recommended conventions, but the language won't stop you from breaking them - and they don't give a distinction between classes and interfaces.


It all depends on the convention that the development teams are using. However, as a practice in java(including JDK) interface names are not different from classnames in terms of convention.


It depends on a naming convention. Some people follow IMap and Map; Map and MapImpl; Map and HashMap and etc. However, if the name is an adjective (like Serializable or Comparable) it is hard to imagine it would be a class. You can also use java.lang.Class.forName("MyInterface").isInterface() for that purpose.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜