From charlesreid1

No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
Default keyword:
Default keyword helps to make [[Java/Interfaces]] work a little bit more like [[Java/Abstract Class]]es.


{{Quote|
{{Quote|
It's a new feature in Java 8 which allows an interface to provide an implementation. Described in Java 8 JLS-13.5.6. Interface Method Declarations which reads (in part)
It's a new feature in Java 8 which allows an interface to provide an implementation. Described in Java 8 JLS-13.5.6. Interface Method Declarations which reads (in part)


"Adding a default method, or changing a method from abstract to default, does not break compatibility with pre-existing binaries, but may cause an IncompatibleClassChangeError if a pre-existing binary attempts to invoke the method. This error occurs if the qualifying type, T, is a subtype of two interfaces, I and J, where both I and J declare a default method with the same signature and result, and neither I nor J is a subinterface of the other."
"Adding a default method, or changing a method from abstract to default, does not break compatibility with pre-existing binaries..."
 
What's New in JDK 8 says (in part)


"Default methods enable new functionality to be added to the interfaces of libraries and ensure binary compatibility with code written for older versions of those interfaces."
"Default methods enable new functionality to be added to the interfaces of libraries and ensure binary compatibility with code written for older versions of those interfaces."
Line 20: Line 18:
[[Category:Interfaces]]
[[Category:Interfaces]]
[[Category:Inheritance]]
[[Category:Inheritance]]
{{CSFlag}}

Latest revision as of 22:22, 15 August 2017

Default keyword helps to make Java/Interfaces work a little bit more like Java/Abstract Classes.


It's a new feature in Java 8 which allows an interface to provide an implementation. Described in Java 8 JLS-13.5.6. Interface Method Declarations which reads (in part)

"Adding a default method, or changing a method from abstract to default, does not break compatibility with pre-existing binaries..."

"Default methods enable new functionality to be added to the interfaces of libraries and ensure binary compatibility with code written for older versions of those interfaces."

- source






See also: