您是否使用(或定义)非标准注释,以及出于何种原因.递归注释怎么样?

Ing*_*ngo 6 java annotations javac

问题告诉了一切.

对于专家来说,SUN java 5编译器是否有理由接受递归注释(与langspec相反),而后来的编译器却没有?我的意思是,什么可能是反对递归注释的论据.

编辑:递归注释类似于:

@Panel(layout=BorderLayout.class,
    nested={
        @Panel(region=NORTH, layout=FlowLayout.class, ...)
        @Panel(region=SOUTH, layout=FlowLayout.class, ...)
    }
)
Run Code Online (Sandbox Code Playgroud)

Sco*_*eld 2

首先——我不确定你所说的递归注释是什么意思。您的意思是可以包含对同一类型的其他注释的引用的注释吗?就像是

@Panel(layout=BorderLayout.class,
    nested={
        @Panel(region=NORTH, layout=FlowLayout.class, ...)
        @Panel(region=SOUTH, layout=FlowLayout.class, ...)
    }
)
Run Code Online (Sandbox Code Playgroud)

(如果可能的话,这将是我想使用它的一个例子......)

至于我对自定义注释(和处理器)的使用:代码生成。

请参阅http://code.google.com/p/javadude/wiki/Annotations

例如,JavaBean 属性:

@Bean(
    properties={    
      @Property(name="name"),
      @Property(name="phone", bound=true),
      @Property(name="friend", type=Person.class, kind=PropertyKind.LIST)
    }
)
public class Person extends PersonGen {
    // generated superclass PersonGen will contain getters/setters
    //    field definitions, property change support...
}
Run Code Online (Sandbox Code Playgroud)

或混合示例

package sample;

import java.util.List;

public interface IFlightAgent {
    List<IFlight> getFlight();
    void reserve(IFlight flight);
}

public interface ICarAgent {
    List<ICar> getCars();
    void reserve(ICar car);
}

public interface IHotelAgent {
    List<IHotel> getHotels();
    void reserve(IHotel hotel);
}

package sample;

import com.javadude.annotation.Bean;
import com.javadude.annotation.Delegate;

@Bean(delegates = {
    @Delegate(type = IHotelAgent.class,
              property = "hotelAgent",
              instantiateAs = HotelAgentImpl.class),
    @Delegate(type = ICarAgent.class,
              property = "carAgent",
              instantiateAs = CarAgentImpl.class),
    @Delegate(type = IFlightAgent.class,
              property = "flightAgent",
              instantiateAs = FlightAgentImpl.class)
    }
)
public class TravelAgent extends TravelAgentGen
    implements IHotelAgent, ICarAgent, IFlightAgent
{
    // generated superclass TravelAgentGen will create instances
    //   of the "instantiateAs" classes and delegate the interface
    //   methods to them
}
Run Code Online (Sandbox Code Playgroud)

请参阅Java 中注释处理的缺点?以及我对其使用的一些潜在问题的回答。