Come aggiungere riferimento a un parametro di metodo in javadoc?


313

Esiste un modo per aggiungere riferimenti a uno o più parametri di un metodo dall'ente di documentazione del metodo? Qualcosa di simile a:

/**
 * 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)
{...}

Risposte:


367

Per quanto ne so dopo aver letto i documenti per Javavoc non esiste tale caratteristica.

Non usare <code>foo</code>come raccomandato in altre risposte; puoi usare {@code foo}. Questo è particolarmente utile quando si fa riferimento a un tipo generico come {@code Iterator<String>}- sicuramente sembra più bello di <code>Iterator&lt;String&gt;</code>, no?



59

Come puoi vedere in Java Source della classe 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);
}

I riferimenti ai parametri sono circondati da <code></code>tag, il che significa che la sintassi Javadoc non fornisce alcun modo per eseguire tale operazione. (Penso che String.class sia un buon esempio di utilizzo di javadoc).


5
Il tag <code> </code> non fa riferimento a un parametro specifico. Sta formattando la parola "String" in testo "dall'aspetto di codice".
— Naxos84

46

Il modo corretto di fare riferimento a un parametro di metodo è il seguente:

inserisci qui la descrizione dell'immagine


2
Questo non aggiunge nulla alle risposte esistenti. Per favore cancellalo.
— Suriv

27
Non solo risponde alla domanda, ma spiega visivamente come modificare Javadoc con un parametro usando un IDE come Intellij. Ciò sarà utile per i ricercatori che cercano una risposta.
— Eurig Jones,

1
Su Eclipse non funziona. Ma è comunque una bella risposta
— Henrique de Sousa l'

2
questo dovrebbe essere cancellato. immaginare non esiste più.
— user4504267,

2
@ user4504267 L'immagine sembra a posto, almeno adesso.
— ErikE,

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.