gpt4 book ai didi

java - 如何使用 Javadoc 显示方法的实现

转载 作者:行者123 更新时间:2023-12-01 09:04:51 25 4
gpt4 key购买 nike

即使听起来不像 BP,我也想知道是否有任何方法可以在 JavaDoc 上显示方法的实现。

我想知道是否有任何类似“@code”的东西可以自动显示而不是描述它的实现。

最佳答案

确实没有办法自动生成代码,最好的方法是执行以下操作。

您可以向文档添加 @apiNote 注释并添加:

/**
* @apiNote
* Description of example implementation...
*
* <pre>{@code
* // Code implementation example.
* }</pre>
*/

Java 8 JDK 的示例

通过 GrepCode:

JDK / jdk / openjdk / 8u40-b25 / java.util.Comparator

GrepCode java.util.Comparator.thenComparing

JDK 8更新112源代码

/**
* Returns a lexicographic-order comparator with another comparator.
* If this {@code Comparator} considers two elements equal, i.e.
* {@code compare(a, b) == 0}, {@code other} is used to determine the order.
*
* <p>The returned comparator is serializable if the specified comparator
* is also serializable.
*
* @apiNote
* For example, to sort a collection of {@code String} based on the length
* and then case-insensitive natural ordering, the comparator can be
* composed using following code,
*
* <pre>{@code
* Comparator<String> cmp = Comparator.comparingInt(String::length)
* .thenComparing(String.CASE_INSENSITIVE_ORDER);
* }</pre>
*
* @param other the other comparator to be used when this comparator
* compares two objects that are equal.
* @return a lexicographic-order comparator composed of this and then the
* other comparator
* @throws NullPointerException if the argument is null.
* @since 1.8
*/
default Comparator<T> thenComparing(Comparator<? super T> other) {
Objects.requireNonNull(other);
return (Comparator<T> & Serializable) (c1, c2) -> {
int res = compare(c1, c2);
return (res != 0) ? res : other.compare(c1, c2);
};
}

关于java - 如何使用 Javadoc 显示方法的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41366944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com