Don't know. What I do know is that all interface methods are implicitly public (at least as far as Java8) and clone() has protected access, so it must be implemented as public so you must give your implementing classes a new implementation, so it isn't an abstract method. If I try to compile this sort of code:-I get this error message:-
Quazi Irfan wrote:. . . At the location of @Override . . . "Method does not override method from it's superclass".
. . . error: clone() in Object cannot implement clone() in functionalInterface
class Foo implements functionalInterface
attempting to assign weaker access privileges; was public
Which IDE? Have you tried it on Eclipse? That sometimes gives you better error messages than NetBeans, which uses the standard Oracle compiler. I got exactly the same error messages from the command line with the Oracle compiler (JDK10.0.1)
And at the location of @FunctionalInterface, IDE reports error saying "Multiple non-overriding abstract methods found in interface functionalIterface"
Quazi Irfan wrote:Ok, I think I've got it - Methods in Object class have different relationship with interfaces.
In the 1st code: Multiple abstract methods are allowed only if other methods are public methods from Object class. That's why the first code with toString() works.
In the 2nd code: clone() is not a public method of Object, therefore IntellijIDEA think it's a second abstract method in a functional interface, which is not allowed.
Am I right?
Quazi Irfan wrote:In the 2nd code: clone() is not a public method of Object, therefore IntellijIDEA think it's a second abstract method in a functional interface, which is not allowed.
Am I right?
Stephan van Hulst wrote:You can not lower visibility of a method.
No. Because of the lower visibility, it is regarded as a syntax error.
Quazi Irfan wrote:. . . Because of changing the visibility, IDE is considering it as a non-overridden method, right?
Go back to the JLS section I posted yesterday. You will there find that interfaces don't have clone() and finalize() methods implicitly, so in the case of the interface, that is a new method, so it can't be considered to override aything. In the implementing classes, clone() and finalize() would have to be overridden specifically, otherwise it is a syntax error because they have protected visibility and they are claiming to implement a method inherited from the interface with public visibility.
Quazi Irfan wrote:. . . IDE is considering it as a non-overridden method, right?
Campbell Ritchie wrote:As you will see, that becomes a compiler error because of the access modifier.
Did you read the JLS llink from Friday? The interface doesn't have an implicit clone() method to override.
Stephan van Hulst wrote:No, it wouldn't. If you leave @FunctionalInterface and remove @Override, you get this error message:
Your mind is under my control .... your will is now mine .... read this tiny ad
Create Edit Print & Convert PDF Using Free API with Javahttps://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire