Bagaimana cara menambahkan referensi ke parameter metode di javadoc?


313

Apakah ada cara untuk menambahkan referensi ke satu atau lebih parameter metode dari badan dokumentasi metode? Sesuatu seperti:

/**
 * When {@paramref a} is null, we rely on b for the discombobulation.
 *
 * @param a this is one of the parameters
 * @param b another param
 */
void foo(String a, int b)
{...}

Jawaban:


367

Sejauh yang saya tahu setelah membaca dokumen untuk javadoc tidak ada fitur seperti itu.

Jangan gunakan <code>foo</code>seperti yang disarankan dalam jawaban lain; Anda dapat menggunakan {@code foo}. Ini sangat baik untuk diketahui ketika Anda merujuk pada jenis generik seperti {@code Iterator<String>}- tentu saja terlihat lebih bagus daripada <code>Iterator&lt;String&gt;</code>, bukan!


@codetag dijelaskan dalam Javadoc - Deskripsi Tag . Lihat Contoh penggunaan dalam kode JDK8 .
— pba

59

Seperti yang Anda lihat di Sumber Java dari kelas java.lang.String:

/**
 * Allocates a new <code>String</code> that contains characters from
 * a subarray of the character array argument. The <code>offset</code>
 * argument is the index of the first character of the subarray and
 * the <code>count</code> argument specifies the length of the
 * subarray. The contents of the subarray are copied; subsequent
 * modification of the character array does not affect the newly
 * created string.
 *
 * @param      value    array that is the source of characters.
 * @param      offset   the initial offset.
 * @param      count    the length.
 * @exception  IndexOutOfBoundsException  if the <code>offset</code>
 *               and <code>count</code> arguments index characters outside
 *               the bounds of the <code>value</code> array.
 */
public String(char value[], int offset, int count) {
    if (offset < 0) {
        throw new StringIndexOutOfBoundsException(offset);
    }
    if (count < 0) {
        throw new StringIndexOutOfBoundsException(count);
    }
    // Note: offset or count might be near -1>>>1.
    if (offset > value.length - count) {
        throw new StringIndexOutOfBoundsException(offset + count);
    }

    this.value = new char[count];
    this.count = count;
    System.arraycopy(value, offset, this.value, 0, count);
}

Referensi parameter dikelilingi oleh <code></code>tag, yang berarti bahwa sintaksis Javadoc tidak menyediakan cara apa pun untuk melakukan hal seperti itu. (Saya pikir String.class adalah contoh penggunaan javadoc yang baik).


5
Tag <code> </code> tidak merujuk parameter tertentu. Ini memformat kata "String" ke dalam teks "code looking".
— Naxos84

46

Cara yang benar merujuk ke parameter metode adalah seperti ini:

masukkan deskripsi gambar di sini


2
Ini tidak menambahkan apa pun ke jawaban yang ada. Silakan hapus itu.
— suriv

27
Tidak hanya menjawab pertanyaan, tetapi secara visual menjelaskan cara mengubah Javadoc dengan parameter menggunakan IDE seperti Intellij. Ini akan bermanfaat bagi pencari yang mencari jawaban.
— Eurig Jones

1
Di Eclipse itu tidak berfungsi. Tapi tetap saja ini jawaban yang bagus
— Henrique de Sousa

2
ini harus dihapus. bayangkan tidak ada lagi.
— user4504267

2
@ user4504267 Gambar terlihat baik-baik saja, setidaknya sekarang.
— ErikE

Dengan menggunakan situs kami, Anda mengakui telah membaca dan memahami Kebijakan Cookie dan Kebijakan Privasi kami.
Licensed under cc by-sa 3.0 with attribution required.