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 class SoapService extends Object { /** Creates new SoapService */ public SoapService() { } /** This is the SOAP exposes method */ public String sayGreeting(String name) { return "Hello "+name; } }
What's with the 'extends Object' syntax ? I've never encountered this kind of syntax (only on Generics).
Does this syntax has any purpose or is 'plain dumb' ?
extends Object> means you can pass an Object or a sub-class that extends Object class. ArrayList<? extends Number> numberList = new ArrayList<Number>(); //Number of subclass numberList = new ArrayList<Integer>(); //Integer extends Number numberList = new ArrayList<Float>(); // Float extends Number.
The extends keyword extends a class (indicates that a class is inherited from another class). In Java, it is possible to inherit attributes and methods from one class to another. We group the "inheritance concept" into two categories: subclass (child) - the class that inherits from another class.
extends Object> is a bounded wildcard (an unknown that extends Object , whereas <E extends Object> is type bounded ( E requires a Parameterized type that extends Object ).
Object does in fact not have an extends clause (and because the Object class is primordial and has special treatment in the spec, there's no extends Object implicitly present). Additionally, you may observe that the value of Object.
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.
All objects in Java implicitly extend Object
, so I'd say it's redundant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With