Home  >  Article  >  Java  >  Instructions for using @Inherited annotation in Java

Instructions for using @Inherited annotation in Java

PHPz
PHPzforward
2023-04-20 16:49:081677browse

Explanation

1. The tag indicates that the type of a certain tag is inherited. The annotation type modified by @inherited is used for class, and the annotation is used for subclasses of class. @inheritedannotation The type is a subclass of the marked class.

Function

2. Allow subclasses to inherit parent class annotations.

Instance

The annotation mark used by MyParentClass is @Inherited, and subclasses can inherit annotation information.

java.lang.annotation.Inherited
@Inherited
public @interface MyCustomAnnotation {
}
 
@MyCustomAnnotation
public class MyParentClass {
  ...
}
 
public class MyChildClass extends MyParentClass {
   ...
}

What collection classes are there in Java?

Collections in Java are mainly divided into four categories:

1. List: ordered, repeatable;

2. Queue: ordered and repeatable;

3. Set: non-repeatable;

4. Map: unordered, with unique keys and non-unique values.

The above is the detailed content of Instructions for using @Inherited annotation in Java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete