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

      <legend id='NUOMp'><style id='NUOMp'><dir id='NUOMp'><q id='NUOMp'></q></dir></style></legend>

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

      <tfoot id='NUOMp'></tfoot>
      • <bdo id='NUOMp'></bdo><ul id='NUOMp'></ul>

      1. Android Studio 中@override 的含义

        时间:2023-09-28
      2. <i id='cbO0v'><tr id='cbO0v'><dt id='cbO0v'><q id='cbO0v'><span id='cbO0v'><b id='cbO0v'><form id='cbO0v'><ins id='cbO0v'></ins><ul id='cbO0v'></ul><sub id='cbO0v'></sub></form><legend id='cbO0v'></legend><bdo id='cbO0v'><pre id='cbO0v'><center id='cbO0v'></center></pre></bdo></b><th id='cbO0v'></th></span></q></dt></tr></i><div id='cbO0v'><tfoot id='cbO0v'></tfoot><dl id='cbO0v'><fieldset id='cbO0v'></fieldset></dl></div>

          <legend id='cbO0v'><style id='cbO0v'><dir id='cbO0v'><q id='cbO0v'></q></dir></style></legend>
          • <bdo id='cbO0v'></bdo><ul id='cbO0v'></ul>

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

                  <tbody id='cbO0v'></tbody>

                  <tfoot id='cbO0v'></tfoot>
                • 本文介绍了Android Studio 中@override 的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我是 Android Studio 的新手,我想知道 Android Studio 中 @Override 语句的用途.

                  I am completely new to Android Studio and I want to know the purpose of the @Override statement in Android Studio.

                  推荐答案

                  @Override 是一个 Java 注释.它告诉编译器以下方法 覆盖 其 超类.例如,假设您实现了一个 Person 类.

                  @Override is a Java annotation. It tells the compiler that the following method overrides a method of its superclass. For instance, say you implement a Person class.

                  public class Person {
                     public final String firstName;
                     public final String lastName;
                  
                     //some methods
                  
                     @Override public boolean equals(Object other) {
                        ...
                     }
                  }
                  

                  person 类有一个 equals() 方法.equals 方法已经在 Person 的超类 Object.因此,上面的 equals() 实现是对 Persons 的 equals() 的重新定义.也就是说,Person 覆盖了 equals().

                  The person class has an equals() method. The equals method is already defined in Person's superclass Object. Therefore the above implementation of equals() is a redefinition of equals() for Persons. That is to say, Person overrides equals().

                  在没有显式注释的情况下覆盖方法是合法的.那么@Override 注释有什么用呢?如果您不小心尝试以这种方式覆盖 equals() 怎么办:

                  It is legal to override methods without explicitly annotating it. So what is the @Override annotation good for? What if you accidentally tried to override equals() that way:

                  public boolean equals(Person other) {
                     ...
                  }
                  

                  上述案例有一个错误.你打算覆盖 equals() 但你没有.为什么?因为真正的 equals() 将 Object 作为参数,而您的 equals() 将 Person 作为参数.编译器不会告诉你这个错误,因为编译器不知道你想要覆盖.据编译器所知,您实际上的意思是 重载 equals().但是,如果您尝试使用 @Override 注释覆盖等于:

                  The above case has a bug. You meant to override equals() but you didn't. Why? because the real equals() gets an Object as a parameter and your equals() gets a Person as a parameter. The compiler is not going to tell you about the bug because the compiler doesn't know you wanted to override. As far as the compiler can tell, you actually meant to overload equals(). But if you tried to override equals using the @Override annotation:

                  @Override public boolean equals(Person other) {
                     ...
                  }
                  

                  现在编译器知道你有一个错误.你想覆盖但你没有.所以使用@Override注解的原因是显式声明方法覆盖.

                  Now the compiler knows that you have an error. You wanted to override but you didn't. So the reason to use the @Override annotation is to explicitly declare method overriding.

                  这篇关于Android Studio 中@override 的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Java注解ElementType常量是什么意思? 下一篇:使用 JPA 时,@Entity 和 @Table 中的 name 参数有什么

                  相关文章

                  最新文章

                    1. <small id='eOWGZ'></small><noframes id='eOWGZ'>

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

                    3. <legend id='eOWGZ'><style id='eOWGZ'><dir id='eOWGZ'><q id='eOWGZ'></q></dir></style></legend>