|
5 | 5 | import java.lang.annotation.RetentionPolicy; |
6 | 6 | import java.lang.annotation.Target; |
7 | 7 |
|
| 8 | +/** |
| 9 | + * Indicates the variance characteristics of a type parameter. |
| 10 | + * <p> |
| 11 | + * This annotation can be used to specify whether a type parameter is |
| 12 | + * covariant, contravariant, or invariant, along with optional depth |
| 13 | + * and strictness settings. |
| 14 | + * </p> |
| 15 | + * |
| 16 | + * <h3>Usage Example:</h3> |
| 17 | + * |
| 18 | + * <pre> |
| 19 | + * {@code |
| 20 | + * public class ImmutableList<@MyVariance(variance = VarianceType.COVARIANT, depth = 100, strict = true) T> { |
| 21 | + * ... |
| 22 | + * } |
| 23 | + * </pre> |
| 24 | + * |
| 25 | + * @see VarianceType |
| 26 | + */ |
8 | 27 | @Retention(RetentionPolicy.SOURCE) |
9 | 28 | @Target(ElementType.TYPE_PARAMETER) |
10 | 29 | public @interface MyVariance { |
| 30 | + /** |
| 31 | + * Specifies the variance type of the annotated type parameter. |
| 32 | + * |
| 33 | + * @return the variance type |
| 34 | + */ |
11 | 35 | public VarianceType variance() default VarianceType.INVARIANT; |
12 | 36 |
|
| 37 | + /** |
| 38 | + * Specifies the depth of variance. This can indicate how deep |
| 39 | + * the variance should apply within type hierarchies. |
| 40 | + * |
| 41 | + * @return the depth of variance |
| 42 | + */ |
13 | 43 | public int depth() default Integer.MAX_VALUE; |
14 | 44 |
|
| 45 | + /** |
| 46 | + * Indicates whether strict variance checking is enforced. |
| 47 | + * |
| 48 | + * <p> |
| 49 | + * If set to true, the compiler will enforce strict variance rules. |
| 50 | + * This means that compilation will fail if the specified variance |
| 51 | + * is not adhered to. If set to false, warnings are logged, but program will still compile. |
| 52 | + * </p> |
| 53 | + * |
| 54 | + * @return true if strict checking is enforced; false otherwise |
| 55 | + */ |
15 | 56 | public boolean strict() default false; |
16 | 57 |
|
17 | 58 | } |
0 commit comments