{"id":416,"date":"2016-05-05T20:11:07","date_gmt":"2016-05-05T17:11:07","guid":{"rendered":"http:\/\/leodev.ru\/blog\/?p=416"},"modified":"2016-05-05T21:13:51","modified_gmt":"2016-05-05T18:13:51","slug":"%d0%b0%d0%bd%d0%bd%d0%be%d1%82%d0%b0%d1%86%d0%b8%d0%b8-%d0%b2-java","status":"publish","type":"post","link":"https:\/\/leodev.ru\/blog\/java\/%d0%b0%d0%bd%d0%bd%d0%be%d1%82%d0%b0%d1%86%d0%b8%d0%b8-%d0%b2-java\/","title":{"rendered":"\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0432 Java"},"content":{"rendered":"<p><strong>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f(<span style=\"color: #bbb529;\">@Annotation<\/span>)<\/strong> \u2014 \u0444\u043e\u0440\u043c\u0430 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0430\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0441\u0430\u043c\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u0432\u043b\u0438\u044f\u043d\u0438\u044f \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u043a\u043e\u0434\u0430, \u043e\u043d\u0438 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u0443\u044e\u0442 \u0435\u0433\u043e \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043b\u0438\u0448\u044c \u043c\u0435\u0442\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e.<\/p>\n<blockquote><p><span style=\"color: #2b386a;\">package java.lang.annotation;<\/span><\/p><\/blockquote>\n<h6>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0442\u0440\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445:<\/h6>\n<ul>\n<li><strong><span style=\"color: #bbb529;\">@Retention<\/span>(RetentionPolicy.<span style=\"color: #8776aa;\">CLASS<\/span>) <\/strong>&#8212;\u00a0\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0432 \u0444\u0430\u0439\u043b\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c, \u043d\u043e \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d JVM\u00a0\u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. <span style=\"text-decoration: underline;\">\u042d\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/span>.<\/li>\n<li><strong><span style=\"color: #bbb529;\">@Retention<\/span>(RetentionPolicy.<span style=\"color: #8776aa;\">SOURCE<\/span>)<\/strong>\u00a0 &#8212; \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0434\u043b\u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0438\u043b\u0438 \u043f\u043e\u0434\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0439 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/lang\/SuppressWarnings.html\" target=\"_blank\">@SuppressWarnings<\/a>;<\/li>\n<li><strong><span style=\"color: #bbb529;\">@Retention<\/span>(RetentionPolicy.<span style=\"color: #8776aa;\">RUNTIME<\/span>)<\/strong> &#8212;<strong>\u00a0<\/strong>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0432 \u0444\u0430\u0439\u043b\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u00a0VM \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0447\u0442\u043e \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0438;<\/li>\n<\/ul>\n<p>\u0410\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0430\u043a\u0435\u0442\u044b, \u043a\u043b\u0430\u0441\u0441\u044b, \u043c\u0435\u0442\u043e\u0434\u044b, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b.<\/p>\n<p><!--more--><\/p>\n<h1>\u041a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c\u00a0\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0432 java<\/h1>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u043e\u0447\u0435\u043d\u044c \u0441\u0445\u043e\u0436\u0438 \u0441 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a\u0430\u043a \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u043e\u043d\u0438\u00a0\u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e <strong>public<\/strong>. \u041c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0442\u0430\u043a \u0436\u0435 \u043a\u0430\u043a \u0438 \u0441 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438 \u043c\u043e\u0436\u043d\u043e\u00a0\u043d\u0435 \u043f\u0438\u0441\u0430\u0442\u044c.<\/p>\n<pre class=\"lang:java decode:true \">@Retention(RetentionPolicy.RUNTIME)\r\n@Target(ElementType.METHOD)\r\npublic @interface SomeName {\r\n    String name() default \"Leo\";\r\n    int value();\r\n}<\/pre>\n<p><span style=\"color: #b00000;\">\u0421\u0438\u043c\u0432\u043e\u043b <strong>@<\/strong><\/span> &#8212; \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443, \u0447\u0442\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f. \u041c\u0435\u0442\u043e\u0434\u044b, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u0441\u043a\u043e\u0440\u0435\u0435 \u043a\u0430\u043a \u043f\u043e\u043b\u044f.<\/p>\n<p><span style=\"color: #b00000;\">@interface<\/span> \u2014 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u044d\u0442\u043e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f<\/p>\n<p><span style=\"color: #b00000;\">default<\/span> \u2014 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043f\u0440\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<h1>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438<\/h1>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f \u0431\u0435\u0437 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u043a\u00a0\u043b\u044e\u0431\u044b\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c: \u043a\u043b\u0430\u0441\u0441\u0430\u043c, \u043c\u0435\u0442\u043e\u0434\u0430\u043c, \u043f\u043e\u043b\u044f\u043c, \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435&#8230;<\/p>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <strong><span style=\"color: #bbb529;\">@Target<\/span><\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c Scope \u0435\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f.<br \/>\n<strong><span style=\"color: #bbb529;\">@Target<\/span>(ElementType.<span style=\"color: #8776aa;\">PACKAGE<\/span>)<\/strong> \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043f\u0430\u043a\u0435\u0442\u043e\u0432;<\/p>\n<p><strong><span style=\"color: #bbb529;\">@Target<\/span>(ElementType.<span style=\"color: #8776aa;\">TYPE<\/span>)<\/strong> \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432;<\/p>\n<p><strong><span style=\"color: #bbb529;\">@Target<\/span>(ElementType.<span style=\"color: #8776aa;\">CONSTRUCTOR<\/span>)<\/strong> \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432;<\/p>\n<p><strong><span style=\"color: #bbb529;\">@Target<\/span>(ElementType.<span style=\"color: #8776aa;\">METHOD<\/span>)<\/strong> \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432;<\/p>\n<p><strong><span style=\"color: #bbb529;\">@Target<\/span>(ElementType.<span style=\"color: #8776aa;\">FIELD<\/span>)<\/strong> \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432(\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445) \u043a\u043b\u0430\u0441\u0441\u0430;<\/p>\n<p><strong><span style=\"color: #bbb529;\">@Target<\/span>(ElementType.<span style=\"color: #8776aa;\">PARAMATER<\/span>)<\/strong> \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430;<\/p>\n<p><strong><span style=\"color: #bbb529;\">@Target<\/span>(ElementType.<span style=\"color: #8776aa;\">LOCAL_VARIABLE<\/span>)<\/strong> \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445.<br \/>\n\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435, \u0447\u0442\u043e \u0431\u044b \u0432\u0430\u0448\u0430 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0447\u0435\u043c \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c <strong>@Target<\/strong> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre class=\"lang:java decode:true \">@Target({ ElementType.PARAMETER, ElementType.LOCAL_VARIABLE })<\/pre>\n<p>\u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 \u0438 \u0434\u043b\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445<\/p>\n<h1>\u041a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e<\/h1>\n<pre class=\"lang:java decode:true\">\/\/\u0410\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \r\n@SomeName(name = \"\u041f\u0440\u0438\u043c\u0435\u0440 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438\", value = 100) \r\npublic static void someMethod() { \r\n    \/\/ some code... \r\n}<\/pre>\n<p>\u041d\u0430\u0448\u0430 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f @someName \u044d\u0442\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0441 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c.<\/p>\n<p><em>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f<\/em> \u044d\u0442\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c <em>\u043c\u0430\u0440\u043a\u0435\u0440<\/em> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e, \u0438 \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u043c\u0430\u0440\u043a\u0435\u0440\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043b\u0435\u0433\u043a\u043e \u043d\u0430\u0439\u0442\u0438 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430 \u0438 \u0447\u0442\u043e \u043d\u0438\u0431\u0443\u0434\u044c \u0441 \u043d\u0438\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<h1>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h1>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0432\u0441\u0435\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 framework\u00a0<strong>JUnit\u00a0<\/strong><\/p>\n<pre class=\"lang:java decode:true\">@Target(ElementType.METHOD)\r\n@Retention(RetentionPolicy.RUNTIME)\r\npublic @interface Test {\r\n    Class expected();\r\n}<\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440. \u042d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0431\u0443\u0434\u0435\u0442 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u043c\u0438\u00a0\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438.<\/p>\n<p>\u041d\u0430\u0448 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Reflection\u00a0\u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c:<\/p>\n<pre class=\"lang:java decode:true\" title=\"\u041f\u0440\u0438\u043c\u0435\u0440 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u0434\u043b\u044f @Test:\">public class TestAnnotationAnalyzer {\r\n    public void analyz(Class&lt;?&gt; clazz) throws Exception {\r\n        Method[] methods = clazz.getMethods();\r\n        int pass = 0;\r\n        int fail = 0;\r\n \r\n        for (Method method : methods) {\r\n            if (method.isAnnotationPresent(Test.class)) {\r\n                \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\r\n                Test test = method.getAnnotation(Test.class);\r\n                Class expected = test.expected();\r\n                try {\r\n                    method.invoke(null);\r\n                    pass++;\r\n                } catch (Exception e) {\r\n                    if (Exception.class != expected) {\r\n                        fail++;\r\n                    } else {\r\n                        pass++;\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n}<\/pre>\n<p>\u0412 <strong>\u0441\u0442\u0440\u043e\u043a\u0435 10<\/strong> \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0443 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u0432 <strong>\u0441\u0442\u0440\u043e\u043a\u0435 11<\/strong> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 Class \u0442\u0430\u043a \u043a\u0430\u043a expected \u2014 \u044d\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c exception.<\/p>\n<p>\u041d\u0443 \u0438 \u0432 <strong>\u0441\u0442\u0440\u043e\u043a\u0435 16\u00a0<\/strong>\u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 Exception \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c.<\/p>\n<blockquote><p>\u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0432 \u044f\u0437\u044b\u043a\u0435 Java \u0441 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0432\u0435\u0440\u0441\u0438\u0438 1.5. \u0412 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u043d\u0438\u0436\u0435 1.5 \u043d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438.<\/p><\/blockquote>\n<p><strong>\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b:<\/strong><\/p>\n<p>https:\/\/docs.oracle.com\/javase\/tutorial\/java\/annotations\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f(@Annotation) \u2014 \u0444\u043e\u0440\u043c\u0430 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0430\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0441\u0430\u043c\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u0432\u043b\u0438\u044f\u043d\u0438\u044f \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u043a\u043e\u0434\u0430, \u043e\u043d\u0438 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u0443\u044e\u0442 \u0435\u0433\u043e \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043b\u0438\u0448\u044c \u043c\u0435\u0442\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. package java.lang.annotation; \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0442\u0440\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445: @Retention(RetentionPolicy.CLASS) &#8212;\u00a0\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0432 \u0444\u0430\u0439\u043b\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c, \u043d\u043e \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d JVM\u00a0\u0432\u043e &hellip; <a href=\"https:\/\/leodev.ru\/blog\/java\/%d0%b0%d0%bd%d0%bd%d0%be%d1%82%d0%b0%d1%86%d0%b8%d0%b8-%d0%b2-java\/\" class=\"more-link\">\u0427\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043b\u0435\u0435<span class=\"screen-reader-text\"> \u00ab\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0432 Java\u00bb<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":419,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89],"tags":[153,154,155,156],"class_list":["post-416","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-annotation","tag-retention","tag-retentionpolicy","tag-156"],"_links":{"self":[{"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/posts\/416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/comments?post=416"}],"version-history":[{"count":7,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/posts\/416\/revisions"}],"predecessor-version":[{"id":429,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/posts\/416\/revisions\/429"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/media\/419"}],"wp:attachment":[{"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/media?parent=416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/categories?post=416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leodev.ru\/blog\/wp-json\/wp\/v2\/tags?post=416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}