• <i id='vN5U1'><tr id='vN5U1'><dt id='vN5U1'><q id='vN5U1'><span id='vN5U1'><b id='vN5U1'><form id='vN5U1'><ins id='vN5U1'></ins><ul id='vN5U1'></ul><sub id='vN5U1'></sub></form><legend id='vN5U1'></legend><bdo id='vN5U1'><pre id='vN5U1'><center id='vN5U1'></center></pre></bdo></b><th id='vN5U1'></th></span></q></dt></tr></i><div id='vN5U1'><tfoot id='vN5U1'></tfoot><dl id='vN5U1'><fieldset id='vN5U1'></fieldset></dl></div>

      <small id='vN5U1'></small><noframes id='vN5U1'>

      <tfoot id='vN5U1'></tfoot>
      1. <legend id='vN5U1'><style id='vN5U1'><dir id='vN5U1'><q id='vN5U1'></q></dir></style></legend>

          <bdo id='vN5U1'></bdo><ul id='vN5U1'></ul>

        在 Java 7 中的访问修饰符之后放置注释是否合法

        时间:2023-09-27

              <tbody id='3HSZZ'></tbody>
            <legend id='3HSZZ'><style id='3HSZZ'><dir id='3HSZZ'><q id='3HSZZ'></q></dir></style></legend>
            <i id='3HSZZ'><tr id='3HSZZ'><dt id='3HSZZ'><q id='3HSZZ'><span id='3HSZZ'><b id='3HSZZ'><form id='3HSZZ'><ins id='3HSZZ'></ins><ul id='3HSZZ'></ul><sub id='3HSZZ'></sub></form><legend id='3HSZZ'></legend><bdo id='3HSZZ'><pre id='3HSZZ'><center id='3HSZZ'></center></pre></bdo></b><th id='3HSZZ'></th></span></q></dt></tr></i><div id='3HSZZ'><tfoot id='3HSZZ'></tfoot><dl id='3HSZZ'><fieldset id='3HSZZ'></fieldset></dl></div>
              <bdo id='3HSZZ'></bdo><ul id='3HSZZ'></ul>

              1. <small id='3HSZZ'></small><noframes id='3HSZZ'>

                  <tfoot id='3HSZZ'></tfoot>
                • 本文介绍了在 Java 7 中的访问修饰符之后放置注释是否合法?还是 Java 8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  这是通常的代码:

                  @Autowire
                  private Service service;
                  

                  但是对于 Java 7,这也可以(并且更短):

                  But with Java 7 this also works (and shorter):

                  private @Autowire Service service;
                  

                  这在 Java 8 中合法吗(具有相同的语义)?这是不好的编码习惯吗?

                  Is that legal in Java 8 (have same semantic)? Is that bad coding practice?

                  推荐答案

                  根据文档

                  在 Java 7 中:

                  In Java 7 :

                  注解可以应用于声明:类的声明,字段、方法和其他程序元素.当用于声明时,每个注释通常会单独出现,按照惯例行.

                  Annotations can be applied to declarations: declarations of classes, fields, methods, and other program elements. When used on a declaration, each annotation often appears, by convention, on its own line.

                  从 Java SE 8 版本开始,注解也可以应用于类型的使用.:

                  As of the Java SE 8 release, annotations can also be applied to the use of types. :

                  类实例创建表达式:

                  new @Interned MyObject();
                  

                  类型转换:

                  myString = (@NonNull String) str;
                  

                  实现子句:

                  class UnmodifiableList<T> implements
                      @Readonly List<@Readonly T> { ... }
                  

                  抛出异常声明:

                  void monitorTemperature() throws
                      @Critical TemperatureException { ... }
                  

                  这篇关于在 Java 7 中的访问修饰符之后放置注释是否合法?还是 Java 8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何注释Java中的类的弃用? 下一篇:注释中的泛型类型

                  相关文章

                  最新文章

                  1. <i id='sr5fp'><tr id='sr5fp'><dt id='sr5fp'><q id='sr5fp'><span id='sr5fp'><b id='sr5fp'><form id='sr5fp'><ins id='sr5fp'></ins><ul id='sr5fp'></ul><sub id='sr5fp'></sub></form><legend id='sr5fp'></legend><bdo id='sr5fp'><pre id='sr5fp'><center id='sr5fp'></center></pre></bdo></b><th id='sr5fp'></th></span></q></dt></tr></i><div id='sr5fp'><tfoot id='sr5fp'></tfoot><dl id='sr5fp'><fieldset id='sr5fp'></fieldset></dl></div>
                      <tfoot id='sr5fp'></tfoot>
                        <bdo id='sr5fp'></bdo><ul id='sr5fp'></ul>
                      <legend id='sr5fp'><style id='sr5fp'><dir id='sr5fp'><q id='sr5fp'></q></dir></style></legend>

                      <small id='sr5fp'></small><noframes id='sr5fp'>