Does 'extends Object' have a purpose or is it redundant?

前端 未结 18 876
日久生厌
日久生厌 2021-01-03 19:25

Following a tutorial on the internet regarding Soap development with Java, I found this link, with a rather unusual code for myself.

The code:

public         


        
相关标签:
18条回答
  • 2021-01-03 19:55

    It just means it inherits directly from the Object class. Here is more about inheritance in Java.

    0 讨论(0)
  • 2021-01-03 19:56

    No. It's just explicitly doing something that is implicit.

    0 讨论(0)
  • 2021-01-03 19:57

    There is one possibility and that is the person who made it don't want you to extend any classes. You can always do a workaround of course but that is the only thing I can come up with that makes sense.

    0 讨论(0)
  • 2021-01-03 19:58

    As a matter of fact, it does not seem to be simply redundant, especially when working in the JWS webservices environment.

    When defining a class for an XML type to be transported over SOAP, I use the wsimport tool to fetch client dependencies from the WSDL, which creates package-local copies of these classes. By explicitly extending Object, one can seamlessly cast between the classes from the two distinct packages.

    Not doing so leads to a compilation error when trying to use a class method from package A that expects an argument type of the class in in package A, and passing in an object generated from the equivalent class in package B.

    0 讨论(0)
  • 2021-01-03 20:01

    Why not make it explicit?

    I'm for adding it in - not everyone "implicitly" knows that every Java class implicitly extends Object. By writing it explicitly they don't have to guess.

    0 讨论(0)
  • 2021-01-03 20:02

    Unless the Object class is not actually the java.lang.Object class (the tutorial does not include the imports, so it's hard to see), the extends Object is redundant.

    0 讨论(0)
提交回复
热议问题