1

如果我正在创建一个抽象类或接口并希望提供有关抽象方法的一些详细信息,有没有办法从该方法的抽象类/接口自动导入注释?

例如:Letterimplements Shippable,我希望评论自动导入。我知道${see_to_overridden},我更喜欢直接注入抽象方法的注释

public interface  Shippable{

    /*
     * returns boolean based on your class's criteria for if it needs to be insured
     * if your parcel type is not insurable just leave as false
     */
        boolean isInsured();

        String shippingMethod();

}

public class Letter implements Insurable{

        /*
     * returns boolean based on your class's criteria for if it needs to be insured
     * if your parcel type is not insurable just leave as false
     */
    boolean isInsured(){
             return false;
        }

}
4

1 回答 1

3

在子类注释中,您可以使用{@inheritDoc}要插入超类文档的位置。您还需要使您的注释符合 JavaDoc 约定——最重要的是,它们以/**代替开头/*(感谢@Puce 指出)。

public interface Shippable{

    /**
     * returns boolean based on your class's criteria for if it needs to be insured
     * if your parcel type is not insurable just leave as false
     */
    boolean isInsured();

    String shippingMethod();
}

public class Letter implements Insurable{

    /**
     * some subclass-specific comments here (optional)
     * {@inheritDoc}
     * more subclass-specific comments here (optional)
     */
    boolean isInsured(){
        return false;
    }
}
于 2012-11-14T18:10:05.297 回答