覆盖Javadoc对java.lang.Enum.values()的注释 [英] Overriding Javadoc comment on java.lang.Enum.values()

查看:224
本文介绍了覆盖Javadoc对java.lang.Enum.values()的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常具体的问题,方法 java.lang.Enum .values()。

I have a very specific problem about the method java.lang.Enum.values().

我想覆盖其javadoc。很明确地说,当我创建了我自己的枚举之后,目前的javadoc是:

I would like to override its javadoc. Very precisely, the current javadoc for this is, after I created my own enum:

public static MyClass.MyEnum[] values()

  ... 
  This method may be used to iterate over the constants as follows:

    for (MyClass.MyEnum c : MyClass.MyEnum.values())
    System.out.println(c);

  Returns:
    ...

但这里系统。电话被认为是不好的做法,所以我希望它不被显示。我的第一个尝试是覆盖 values(),但显然是不可能的。还有另一种方式可以做到吗?或者是在maven端执行某些操作的唯一可能性?

But here System.out calls are considered bad practice so I would like it not to be shown. My first try was to override values() but apparently it is not possible. Is there another way I can do this? Or is the only possibility to do something on maven side?

我也很好奇为什么 values()不可覆盖我阅读了其他问题它是由编译器生成的 。但有人可以更准确吗?看来它是从枚举的名字生成的,但这并不能解释为什么。

I am also curious about why values() is not overridable. I read on other questions that "it is generated by the compiler". But can someone be more precise? It seems that it's generated from the enum's name, but it does not explain why.

推荐答案

values 是一个静态方法,不会被覆盖。您不能提供自己的方法来替换生成的方法,而这是通过规范

values is a static method and is not subject to overriding. You cannot provide your own method to replace the generated one, and this is by specification.

没有标准的机制来替换不能控制其源代码的方法的Javadoc,但是可能使用构建工具,或者如果其他所有操作都失败,最后的Javadoc HTML。

There is no standard mechanism to replace the Javadoc of a method whose source code you don't control, but you could probably mess around with either the build tool, or, if all else fails, the final Javadoc HTML.

这篇关于覆盖Javadoc对java.lang.Enum.values()的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆