[java] javadoc에서 메소드를 참조하는 방법은 무엇입니까?

@link태그를 사용하여 메소드에 링크하려면 어떻게해야합니까?

나는 바꾸고 싶다:

/**
 * Returns the Baz object owned by the Bar object owned by Foo owned by this.
 * A convenience method, equivalent to getFoo().getBar().getBaz()
 * @return baz
 */
public Baz fooBarBaz()

에:

/**
 * Returns the Baz object owned by the Bar object owned by Foo owned by this.
 * A convenience method, equivalent to {@link getFoo()}.{@link getBar()}.{@link getBaz()}
 * @return baz
 */
public Baz fooBarBaz()

하지만 @link태그의 형식을 올바르게 지정 하는 방법을 모르겠습니다 .



답변

Java Doc에 대한 정보를 포함하여 표준 DocletDocumentation Comment Specification 에서 JavaDoc에 대한 많은 정보를 찾을 수 있습니다.

{@link package.class # member 레이블}

태그 (당신이 찾고있는). 문서의 해당 예는 다음과 같습니다.

예를 들어, 다음은 getComponentAt (int, int) 메소드를 참조하는 주석입니다.

Use the {@link #getComponentAt(int, int) getComponentAt} method.

package.class참조한 방법은 현재 클래스의 경우 부분 ommited 수있다.


JavaDoc에 대한 다른 유용한 링크는 다음과 같습니다.


답변

javadoc documentation@link 섹션 에서 일반적인 형식 은 다음과 같습니다.

{@link package.class # member 레이블}

같은 클래스의 메소드 :

/** See also {@link #myMethod(String)}. */
void foo() { ... }

동일한 패키지에 있거나 가져온 다른 클래스의 메소드 :

/** See also {@link MyOtherClass#myMethod(String)}. */
void foo() { ... }

다른 패키지에 있고 가져 오지 않은 메소드 :

/** See also {@link com.mypackage.YetAnotherClass#myMethod(String)}. */
void foo() { ... }

코드 글꼴이 아닌 일반 텍스트로 메서드에 연결된 레이블 :

/** See also this {@linkplain #myMethod(String) implementation}. */
void foo() { ... }

귀하의 질문 같이 일련의 메소드 호출 . 이 클래스 외부의 메소드에 대한 링크 레이블을 지정해야합니다 getFoo().Foo.getBar().Bar.getBaz(). 그러나이 레이블은 깨지기 쉬울 수 있습니다. 아래의 “라벨”을 참조하십시오.

/**
 * A convenience method, equivalent to
 * {@link #getFoo()}.{@link Foo#getBar() getBar()}.{@link Bar#getBaz() getBaz()}.
 * @return baz
 */
public Baz fooBarBaz()

라벨

자동 리팩토링은 레이블에 영향을 미치지 않을 수 있습니다. 여기에는 메소드, 클래스 또는 패키지 이름 바꾸기가 포함됩니다. 메소드 서명 변경

따라서 기본 텍스트와 다른 텍스트를 원하는 경우 에만 레이블을 제공하십시오 .

예를 들어, 인간 언어에서 코드로 링크 할 수 있습니다.

/** You can also {@linkplain #getFoo() get the current foo}. */
void setFoo( Foo foo ) { ... }

또는 위의 “메소드 호출 체인”에 표시된 것처럼 기본값과 다른 텍스트로 코드 샘플에서 링크 할 수 있습니다. 그러나 API가 발전하는 동안 이것은 취약 할 수 있습니다.

유형 삭제 및 # 멤버

메소드 서명에 매개 변수화 된 유형이 포함 된 경우 javadoc @link에서 해당 유형의 지우기를 사용하십시오. 예를 들면 다음과 같습니다.

int bar( Collection<Integer> receiver ) { ... }

/** See also {@link #bar(Collection)}. */
void foo() { ... }


답변

당신은 @see그것을 할 수 있습니다 :

견본:

interface View {
        /**
         * @return true: have read contact and call log permissions, else otherwise
         * @see #requestReadContactAndCallLogPermissions()
         */
        boolean haveReadContactAndCallLogPermissions();

        /**
         * if not have permissions, request to user for allow
         * @see #haveReadContactAndCallLogPermissions()
         */
        void requestReadContactAndCallLogPermissions();
    }


답변