<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FLanguage%2FStandard_Annotations</id>
		<title>Java Tutorial/Language/Standard Annotations - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FLanguage%2FStandard_Annotations"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Language/Standard_Annotations&amp;action=history"/>
		<updated>2026-04-24T09:34:55Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/Language/Standard_Annotations&amp;diff=4878&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Language/Standard_Annotations&amp;diff=4878&amp;oldid=prev"/>
				<updated>2010-06-01T05:06:46Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 05:06, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/Language/Standard_Annotations&amp;diff=4877&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Language/Standard_Annotations&amp;diff=4877&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:27Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==  A demo for SuppressWarnings: unchecked and fallthrough warnings ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Uses the SuppressWarnings annotation type to prevent the compiler from issuing unchecked and fallthrough warnings&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.Serializable;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
@SuppressWarnings (value={&amp;quot;unchecked&amp;quot;, &amp;quot;serial&amp;quot;})&lt;br /&gt;
public class SuppressWarningsTest implements Serializable {&lt;br /&gt;
    public void openFile () {&lt;br /&gt;
        ArrayList a = new ArrayList ();&lt;br /&gt;
        File file = new File (&amp;quot;X:/java/doc.txt&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Documented ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;Documented is a marker annotation type used to annotate the declaration of an annotation type so that instances of the annotation type will be included in the documentation.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;Override annotation type is not annotated using Documented.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;Deprecated annotation type is annotated @Documented.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  How do I mark method as deprecated? ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.util.Calendar;&lt;br /&gt;
import java.util.Date;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    getDate();&lt;br /&gt;
    getMonthFromDate();&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get current system date.&lt;br /&gt;
   * &lt;br /&gt;
   * @return current system date.&lt;br /&gt;
   * @deprecated This method will removed in the near future.&lt;br /&gt;
   */&lt;br /&gt;
  @Deprecated&lt;br /&gt;
  public static Date getDate() {&lt;br /&gt;
    return new Date();&lt;br /&gt;
  }&lt;br /&gt;
  public static int getMonthFromDate() {&lt;br /&gt;
    return Calendar.getInstance().get(Calendar.MONTH);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Inherited ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;Use Inherited to annotate an annotation type, any instance of the annotation type will be inherited.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;Use Inherited to annotate a class, the annotation will be inherited by any subclass of the annotated class. If the user queries the annotation type on a class declaration, and the class declaration has no annotation of this type, then the class&amp;quot;s parent class will automatically be queried for the annotation type. This process will be repeated until an annotation of this type is found or the root class is reached.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Insert an annotation to suppress warning ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.Iterator;&lt;br /&gt;
public class Main {&lt;br /&gt;
  @SuppressWarnings(&amp;quot;unchecked&amp;quot;)&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    ArrayList data = new ArrayList();&lt;br /&gt;
    data.add(&amp;quot;hello&amp;quot;);&lt;br /&gt;
    data.add(&amp;quot;world&amp;quot;);&lt;br /&gt;
    Iterator it = data.iterator();&lt;br /&gt;
    while (it.hasNext()) {&lt;br /&gt;
      System.out.println(it.next());&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Retention ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;@Retention indicates how long annotations whose annotated types are annotated @Retention are to be retained.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;The value of @Retention can be one of the members of the java.lang.annotation.RetentionPolicy enum:&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;SOURCE. Annotations are to be discarded by the Java compiler.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;CLASS. Annotations are to be recorded in the class file but not be retained by the JVM. This is the default value.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;RUNTIME. Annotations are to be retained by the JVM so you can query them using reflection.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
@Retention(value=SOURCE)&lt;br /&gt;
public @interface SuppressWarnings&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Standard Annotations: Deprecated ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Deprecated is a marker annotation type that can be applied to a method or a type (class/interface) to indicate that the method or type is deprecated.&lt;br /&gt;
Deprecating a method:&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class DeprecatedTest {&lt;br /&gt;
  @Deprecated&lt;br /&gt;
  public void serve() {&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Standard Annotations: Override ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Override is a marker annotation type that can be applied to a method to indicate to the compiler that the method overrides a method in a superclass. &lt;br /&gt;
This annotation type guards the programmer against making a mistake when overriding a method.&lt;br /&gt;
For example, consider this class Parent:&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
class Parent {&lt;br /&gt;
    public float calculate (float a, float b) {&lt;br /&gt;
        return a * b;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
Whenever you want to override a method, declare the Override annotation type before the method:&lt;br /&gt;
public class Child extends Parent {&lt;br /&gt;
    @Override&lt;br /&gt;
    public int calculate (int a, int b) {&lt;br /&gt;
        return (a + 1) * b;&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Standard Annotations: SuppressWarnings ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;SuppressWarnings is used to suppress compiler warnings. &lt;br /&gt;
You can apply @SuppressWarnings to types, constructors, methods, fields, parameters, and local variables.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The following are valid parameters to @SuppressWarnings:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;unchecked.   Give more detail for unchecked conversion.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;path.        Warn about nonexistent path (classpath, sourcepath, etc) directories.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;serial.      Warn about missing serialVersionUID definitions on serializable classes.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;finally.     Warn about finally clauses that cannot complete normally.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;fallthrough. Check switch blocks for fall-through cases.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
switch (i) {&lt;br /&gt;
      case 1:&lt;br /&gt;
          System.out.println(&amp;quot;1&amp;quot;);&lt;br /&gt;
          break;&lt;br /&gt;
      case 2:&lt;br /&gt;
          System.out.println (&amp;quot;2&amp;quot;);&lt;br /&gt;
          // falling through&lt;br /&gt;
      case 3:&lt;br /&gt;
          System.out.println (&amp;quot;3&amp;quot;);&lt;br /&gt;
      }&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Standard Meta-Annotations ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;Meta annotations are annotations that are applied to annotations.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;There are four meta-annotation types: Documented, Inherited, Retention, and Target.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;All the four are part of the java.lang.annotation package.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Target ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Target indicates which program element(s) can be annotated using instances of the annotated annotation type.&lt;br /&gt;
The value of Target is one of the members of the java.lang.annotation.ElementType enum:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;ANNOTATION_TYPE. The annotated annotation type can be used to annotate annotation type declaration.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;CONSTRUCTOR. The annotated annotation type can be used to annotate constructor declaration.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;FIELD. The annotated annotation type can be used to annotate field declaration.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;LOCAL_VARIABLE. The annotated annotation type can be used to annotate local variable declaration.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;METHOD. The annotated annotation type can be used to annotate method declaration.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;PACKAGE. The annotated annotation type can be used to annotate package declarations.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;PARAMETER. The annotated annotation type can be used to annotate parameter declarations.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;TYPE. The annotated annotation type can be used to annotate type declarations.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
@Target(value=METHOD)&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;You can have multiple values in the Target annotation.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;@Target(value={TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  The Built-In Annotations ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;Java defines seven built-in annotations.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;Four are imported from java.lang.annotation: @Retention, @Documented, @Target, and @Inherited.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;Three, @Override, @Deprecated, and @SuppressWarnings, are included in java.lang.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Use Override annotation ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class Main {&lt;br /&gt;
  private String field;&lt;br /&gt;
  private String attribute;&lt;br /&gt;
  @Override&lt;br /&gt;
  public int hashCode() {&lt;br /&gt;
    return field.hashCode() + attribute.hashCode();&lt;br /&gt;
  }&lt;br /&gt;
  @Override&lt;br /&gt;
  public String toString() {&lt;br /&gt;
    return field + &amp;quot; &amp;quot; + attribute;&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  What is SuppressWarnings annotation? ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.util.Date;&lt;br /&gt;
 &lt;br /&gt;
public class Main {&lt;br /&gt;
    @SuppressWarnings(value={&amp;quot;deprecation&amp;quot;})&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
        Date date = new Date(2009, 9, 30);&lt;br /&gt;
 &lt;br /&gt;
        System.out.println(&amp;quot;date = &amp;quot; + date);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>