2016-12-28 8 views
0

BPとして聞こえない場合でも、メソッドの実装をJavaDocに示す方法があるかどうか疑問に思っていました。Javadocを使用してメソッドの実装を表示する方法

「@ code」のようなものがあれば、自動的にそれを記述するのではなく、その実装を示しているのだろうかと思います。

+0

"BP" とは何ですか? –

+3

JavaDocにコードを表示することは本当に必要ですか? - 私は通常、APIだけがそこにあるべきだと思います。 –

+0

私はそれがとにかくそれを行う方法があるかどうか私はちょうど不思議に思っていた必要はありません知っている。 – OEH

答えて

1

実際にコードを自動的に生成する方法はありません。できることは次のとおりです。

あなたのドキュメントに@apiNote注釈を追加し、追加することができます。Java 8 JDK

経由GrepCodeから

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

例:

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); 
    }; 
} 
関連する問題