java api中接口命名的标准是什么

编程入门 行业动态 更新时间:2024-10-20 13:41:46
本文介绍了java api中接口命名的标准是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

一位同事问我有关java API中的 Throwable 类的问题。

I am asked by one of colleague about the Throwable class in java API.

按照标准,我明白,每个结尾*的单词都是java API中的一个接口。关于使用诸如接口名称之类的单词存在行业标准。所以,我在不知不觉中告诉他这个作为java世界中所有异常和错误类型的基本接口。然后他向我展示了这个类的java文件。

As per standard, I do understand, every word ending *able is a interface in java API. There is a industry standard about using such words as Interface names. So, I unknowingly, told him about this as base interface for all the exception and error types in java world. Then he shows me the java file for this class.

我的问题:

  • 为什么java人选择了这个名字成为一个班级。我认为默认情况下这应该是一个界面?

  • Why java people has choosen this name to be a class. I think this should have been a interface by default?

    这是一种使用* able words作为界面的模式吗?

    Is this a pattern to use *able words as interface?

    是否有其他类以* able结尾的例子?

    Is there any other example of class ending with *able?

    问候。

    推荐答案

    这些'-able'名称在Java中是非常常见的,但是没有官方的接口命名约定我发现这表明'-able'名称应该是接口名称,但通常就是这种情况。

    It's very common for those '-able' names to be interfaces in Java, but there is no official convention for interface naming that I've found that suggests that '-able' names should be interface names, though typically that is the case.

    官方Java命名约定可以在这里找到 - 它是非常精简,对类或接口命名没有任何限制:

    Official Java naming conventions can be found here - it's pretty lean, there really aren't any restrictions for class or interface naming:

    • www.oracle/technetwork/java/codeconventions-135099.html#367
    • www.oracle/technetwork/java/codeconventions-135099.html#367

    至于你的 Throwable 问题,James Gosling曾经回答为什么它是一个类而不是一个接口,即使这个名称更适合接口。

    As to your Throwable question, James Gosling once answered why it's a class rather than an interface, even though the name was more fitting for an interface.

    不幸的是,Sun / Oracle网站上的原始文章已经消失了互联网以太,所以我只能提供间接归属:

    Unfortunately, the original article from Sun/Oracle's site has vanished into the internet ether, so I can only provide indirect attribution:

    • c2/cgi/wiki?JavaExceptionQuestion
    • www.ibm/developerworks/forums/thread.jspa?threadID=58994&tstart=45
    • c2/cgi/wiki?JavaExceptionQuestion
    • www.ibm/developerworks/forums/thread.jspa?threadID=58994&tstart=45

    编辑:由于我继续得到这个问题,我通过 Wayback Machine ,这里: http:/ /web.archive/web/20071013225816/java.sun/features/2002/03/gosling.html?source=jdc_news&date=20020430

    edit: Since I continue to get upvotes to this question, I found the link to the Sun discussion via the Wayback Machine, here: web.archive/web/20071013225816/java.sun/features/2002/03/gosling.html?source=jdc_news&date=20020430

    JDC:为什么Throwable不是接口?这个名字有点暗示它应该是。能够捕获类型,即try {} catch(),而不仅仅是类。这将使Java编程语言更加灵活。

    JDC: Why is Throwable not an interface? The name kind of suggests it should have been. Being able to catch for types, that is, something like try{}catch (), instead of only classes. That would make the Java programming language much more flexible.

    JG:Throwable和其他人不是接口的原因是因为我们决定,或者我决定相当早。 我决定让每个被抛出的异常都与某个状态相关联。你不能用接口做到这一点;你只能用课程来做。那里的状态基本上是标准的。有消息,有一个快照,像那样的东西总是在那里。而且,如果你让Throwable成为一个界面,那么诱惑就是分配,使任何旧的对象成为一个Throwable的东西。从风格上来说,投掷一般物体可能是一个坏主意,你想抛出的东西确实应该是那些真正捕捉异常性质和发生的事情的异常事物。它们不仅仅是一般数据结构。

    JG: The reason that the Throwable and the rest of those guys are not interfaces is because we decided, or I decided fairly early on. I decided that I wanted to have some state associated with every exception that gets thrown. And you can't do that with interfaces; you can only do that with classes. The state that's there is basically standard. There's a message, there's a snapshot, stuff like that that's always there. and also, if you make Throwable an interface the temptation is to assign, to make any old object be a Throwable thing. It feels stylistically that throwing general objects is probably a bad idea, that the things you want to throw really ought to be things that are intended to be exceptions that really capture the nature of the exception and what went on. They're not just general data structures.

  • 更多推荐

    java api中接口命名的标准是什么

    本文发布于:2023-10-09 06:07:38,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1474908.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:接口   标准   java   api

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!