2

I want to find the contents of the java.net.ServerSocket accept() method (because I am trying to override it so it returns a different type). Is this possible in Eclipse, or for that matter, in Java?

Thanks.

Lucas Baizer
  • 189
  • 1
  • 2
  • 10

1 Answers1

1

No, it isn't possible in Java. Because, you can not modify the return type of a function you override. The Java Tutorials Overriding and Hiding Methods says (in part)

An instance method in a subclass with the same signature (name, plus the number and the type of its parameters) and return type as an instance method in the superclass overrides the superclass's method.

I recommend you use the @Override annotation to protect yourself from acidentally overloading a method you intend to override.

Community
  • 1
  • 1
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • For good measure I just changed the return type of the `accept()` method to a class that `extends` `java.net.Socket` and added the `@Override` annotation before the method. Eclipse threw no errors, so does this mean that the overridden method CAN return a class that extends the original return type? – Lucas Baizer Jun 08 '15 at 22:07