{"id":23429,"date":"2014-04-04T16:00:58","date_gmt":"2014-04-04T13:00:58","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=23429"},"modified":"2014-04-04T14:35:35","modified_gmt":"2014-04-04T11:35:35","slug":"java-8-default-methods-what-can-and-can-not-do","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html","title":{"rendered":"Java 8 default methods: what can and can not do?"},"content":{"rendered":"<h2>What default method is<\/h2>\n<p>With the release of Java 8 you can modify interfaces adding new methods so that the interface remains compatible with the classes that implement the interface. This is very important in case you develop a library that is going to be used by several programmers from Kiev to New York. Until the dawn of Java 8 if you published an interface in a library you could not add a new method without risking that some application implementing in the interface will break with the new version of the interface.<\/p>\n<p>With Java 8 this fear is gone? No.<\/p>\n<blockquote>\n<p>Adding a default method to an interface may render some class unusable.<\/p>\n<\/blockquote>\n<p>Let\u2019s see first the fine points of the default method.<\/p>\n<p>In Java 8 a method can be implemented in an interface. (Static methods can also be implemented in an interface as of Java8, but that is another story.) The method implemented in an interface is called default method and is denoted by the keyword <code>default<\/code> as a modifier. When a class implements an interface it may, but does not need to implement a method implemented already in the interface. The class inherits the default implementation. This is why you may not need touch a class when an interface it implements changes.<\/p>\n<h2>Multiple inheritance?<\/h2>\n<p>The things start to get complicated when a concrete class implements more than one (say two) interfaces and the interfaces implement the same default method. Which default method will the class inherit? The answer is none. In such a case the class has to implement the method itself (directly or by inheritance from a higher class).<\/p>\n<p>This is also true when only one of the interfaces implement the default method and the other one only declares it as abstract. Java 8 tries to be disciplined and avoid \u201cimplicit\u201d things. If the methods are declared in more than one interfaces then no default implementation is inherited, you get a compile time error.<\/p>\n<p>However you can not get a compile time error if you have your class already compiled. This way Java 8 is not consistent. It has its reason, which I do not want to detail here or get into debate for various reasons (e.g.: the release is out, debate time is long over and was never on this platform).<\/p>\n<ul>\n<li>Say you have two interfaces, and a class implementing the two interfaces.<\/li>\n<li>One of the interfaces implement a default method <code>m()<\/code>.<\/li>\n<li>You compile all the interfaces and the class.<\/li>\n<li>You change the interface not containing the method <code>m()<\/code> to declare it as an abstract method.<\/li>\n<li>Compile the modified interface only.<\/li>\n<li>Run the class.<\/li>\n<\/ul>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/multiple-inheritance.png\"><img decoding=\"async\" class=\"aligncenter size-medium wp-image-23826\" alt=\"multiple-inheritance\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/multiple-inheritance-300x207.png\" width=\"300\" height=\"207\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/multiple-inheritance-300x207.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/multiple-inheritance.png 1024w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nIn this case the class runs. You can not compile it again with the modified interfaces, but if it was compiled with the older version: it still runs. Now<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<ul>\n<li>modify the interface having the abstract method <code>m()<\/code> and create a default implementation.<\/li>\n<li>Compile the modified interface.<\/li>\n<li>Run the class: failure.<\/li>\n<\/ul>\n<p>When there are two interfaces providing default implementation for the same method the method can not be invoked in the implementing class unless implemented by the class (again: either directly or inherited from another class).<br \/>\n&nbsp;<br \/>\n<a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/multiple-inheritance2.png\"><img decoding=\"async\" class=\"aligncenter size-medium wp-image-23827\" alt=\"multiple-inheritance2\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/multiple-inheritance2-300x196.png\" width=\"300\" height=\"196\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/multiple-inheritance2-300x196.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/multiple-inheritance2-1024x672.png 1024w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/multiple-inheritance2.png 1051w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nThe class is compatible. It can be loaded with the new interface. It can even start execution so long as long there is no invocation to the method having default implementation in both interfaces.<\/p>\n<h2>Sample code<\/h2>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/multiple-inheritance-directory.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-23828\" alt=\"multiple-inheritance-directory\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/multiple-inheritance-directory.png\" width=\"104\" height=\"159\" \/><\/a><\/p>\n<p>To demonstrate the above I created a test directory for the class <code>C.java<\/code> and three subdirectories for the interfaces in files <code>I1.java<\/code> and <code>I2.java<\/code>. The root directory of the test contains the source code for the class <code>C<\/code> in file <code>C.java<\/code>. The directory <code>base<\/code> contains the interface version that is good for execution and compilation. <code>I1<\/code> contains the method <code>m()<\/code> with default implementation. The interface <code>I2<\/code> does not contain any method for now.<\/p>\n<p>The class contains a main method so we can execute it in our test. It tests if there is any command line argument so we can easily execute it with and without invoking the method <code>m()<\/code>.<\/p>\n<pre class=\" brush:java\">~\/github\/test$ cat C.java \r\npublic class C implements I1, I2 {\r\n  public static void main(String[] args) {\r\n    C c = new C();\r\n    if( args.length == 0 ){\r\n      c.m();\r\n    }\r\n  }\r\n}\r\n~\/github\/test$ cat base\/I1.java \r\npublic interface I1 {\r\n  default void m(){\r\n    System.out.println(\"hello interface 1\");\r\n  }\t\r\n}\r\n~\/github\/test$ cat base\/I2.java \r\npublic interface I2 {\r\n}<\/pre>\n<p>We can compile and run the class using the command lines:<\/p>\n<pre class=\" brush:java\">~\/github\/test$ javac -cp .:base C.java\r\n~\/github\/test$ java -cp .:base C\r\nhello interface 1<\/pre>\n<p>The directory <code>compatible<\/code> contains a version of the interface <code>I2<\/code> that declares the method <code>m()<\/code> abstract, and for technical reasons it contains <code>I1.java<\/code> unaltered.<\/p>\n<pre class=\" brush:java\">~\/github\/test$ cat compatible\/I2.java \r\n\r\npublic interface I2 {\r\n  void m();\r\n}<\/pre>\n<p>This can not be used to compile the class <code>C<\/code>:<\/p>\n<pre class=\" brush:java\">~\/github\/test$ javac -cp .:compatible C.java \r\nC.java:1: error: C is not abstract and does not override abstract method m() in I2\r\npublic class C implements I1, I2 {\r\n       ^\r\n1 error<\/pre>\n<p>The error message is very precise. Even though we have the <code>C.class<\/code> from the previous compilation and if we compile the interfaces in the directory <code>compatible<\/code> we will have two interfaces that can still be used to run the class:<\/p>\n<pre class=\" brush:java\">~\/github\/test$ javac compatible\/I*.java\r\n~\/github\/test$ java -cp .:compatible C\r\nhello interface 1<\/pre>\n<p>The third directory, <code>wrong<\/code> contains a version of <code>I2<\/code> that also defines the method <code>m()<\/code>:<\/p>\n<pre class=\" brush:java\">~\/github\/test$ cat wrong\/I2.java \r\npublic interface I2 {\r\n  default void m(){\r\n    System.out.println(\"hello interface 2\");\r\n  }\r\n}<\/pre>\n<p>We should not even bother to compile it. Even though the method is double defined the class still can be executed so long as long it does not invoke the method, but it fails as soon as we try to invoke the method <code>m()<\/code>. This is what we use the command line argument for:<\/p>\n<pre class=\" brush:java wrap-lines:false\">~\/github\/test$ javac wrong\/*.java\r\n~\/github\/test$ java -cp .:wrong C\r\nException in thread \"main\" java.lang.IncompatibleClassChangeError: Conflicting default methods: I1.m I2.m\r\n\tat C.m(C.java)\r\n\tat C.main(C.java:5)\r\n~\/github\/test$ java -cp .:wrong C x\r\n~\/github\/test$<\/pre>\n<h2>Conclusion<\/h2>\n<p>When you start to move your library to Java 8 and you modify your interfaces adding default implementations, you probably will not have problems. At least that is what Java 8 library developers hope adding functional methods to collections. Applications using your library are still relying on Java 7 libraries that do not have default methods. When different libraries are used and modified, there is a slight chance of conflict. What to do to avoid it?<\/p>\n<p>Design your library APIs as before. Do not go easy relying on the possibility of default methods. They are last resort. Choose names wisely to avoid collision with other interfaces. We will learn how Java programming will develop using this feature.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"http:\/\/javax0.wordpress.com\/2014\/03\/26\/the-true-nature-of-java-8-default-methods\/\">Java 8 default methods: what can and can not do?<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Peter Verhas at the <a href=\"http:\/\/javax0.wordpress.com\/\">Java Deep<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>What default method is With the release of Java 8 you can modify interfaces adding new methods so that the interface remains compatible with the classes that implement the interface. This is very important in case you develop a library that is going to be used by several programmers from Kiev to New York. Until &hellip;<\/p>\n","protected":false},"author":539,"featured_media":148,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[196],"class_list":["post-23429","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-java","tag-java-8"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java 8 default methods: what can and can not do?<\/title>\n<meta name=\"description\" content=\"What default method is With the release of Java 8 you can modify interfaces adding new methods so that the interface remains compatible with the classes\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java 8 default methods: what can and can not do?\" \/>\n<meta property=\"og:description\" content=\"What default method is With the release of Java 8 you can modify interfaces adding new methods so that the interface remains compatible with the classes\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/verhas\" \/>\n<meta property=\"article:published_time\" content=\"2014-04-04T13:00:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Peter Verhas\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/verhas\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Peter Verhas\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/04\\\/java-8-default-methods-what-can-and-can-not-do.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/04\\\/java-8-default-methods-what-can-and-can-not-do.html\"},\"author\":{\"name\":\"Peter Verhas\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/7d6f9ea12efb97a251114fe5255549f1\"},\"headline\":\"Java 8 default methods: what can and can not do?\",\"datePublished\":\"2014-04-04T13:00:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/04\\\/java-8-default-methods-what-can-and-can-not-do.html\"},\"wordCount\":939,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/04\\\/java-8-default-methods-what-can-and-can-not-do.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"keywords\":[\"Java 8\"],\"articleSection\":[\"Core Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/04\\\/java-8-default-methods-what-can-and-can-not-do.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/04\\\/java-8-default-methods-what-can-and-can-not-do.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/04\\\/java-8-default-methods-what-can-and-can-not-do.html\",\"name\":\"Java 8 default methods: what can and can not do?\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/04\\\/java-8-default-methods-what-can-and-can-not-do.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/04\\\/java-8-default-methods-what-can-and-can-not-do.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"datePublished\":\"2014-04-04T13:00:58+00:00\",\"description\":\"What default method is With the release of Java 8 you can modify interfaces adding new methods so that the interface remains compatible with the classes\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/04\\\/java-8-default-methods-what-can-and-can-not-do.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/04\\\/java-8-default-methods-what-can-and-can-not-do.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/04\\\/java-8-default-methods-what-can-and-can-not-do.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/04\\\/java-8-default-methods-what-can-and-can-not-do.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/core-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Java 8 default methods: what can and can not do?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/7d6f9ea12efb97a251114fe5255549f1\",\"name\":\"Peter Verhas\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c4bf0144531172dc8ef1aec04c1faabd409f61d458b3b37ae1dc400b42fbf466?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c4bf0144531172dc8ef1aec04c1faabd409f61d458b3b37ae1dc400b42fbf466?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c4bf0144531172dc8ef1aec04c1faabd409f61d458b3b37ae1dc400b42fbf466?s=96&d=mm&r=g\",\"caption\":\"Peter Verhas\"},\"sameAs\":[\"http:\\\/\\\/javax0.wordpress.com\\\/\",\"https:\\\/\\\/www.facebook.com\\\/verhas\",\"http:\\\/\\\/www.linkedin.com\\\/profile\\\/view?id=674424\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/verhas\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/peter-verhas\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java 8 default methods: what can and can not do?","description":"What default method is With the release of Java 8 you can modify interfaces adding new methods so that the interface remains compatible with the classes","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html","og_locale":"en_US","og_type":"article","og_title":"Java 8 default methods: what can and can not do?","og_description":"What default method is With the release of Java 8 you can modify interfaces adding new methods so that the interface remains compatible with the classes","og_url":"https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/verhas","article_published_time":"2014-04-04T13:00:58+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","type":"image\/jpeg"}],"author":"Peter Verhas","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/verhas","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Peter Verhas","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html"},"author":{"name":"Peter Verhas","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/7d6f9ea12efb97a251114fe5255549f1"},"headline":"Java 8 default methods: what can and can not do?","datePublished":"2014-04-04T13:00:58+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html"},"wordCount":939,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","keywords":["Java 8"],"articleSection":["Core Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html","url":"https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html","name":"Java 8 default methods: what can and can not do?","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","datePublished":"2014-04-04T13:00:58+00:00","description":"What default method is With the release of Java 8 you can modify interfaces adding new methods so that the interface remains compatible with the classes","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2014\/04\/java-8-default-methods-what-can-and-can-not-do.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/core-java"},{"@type":"ListItem","position":4,"name":"Java 8 default methods: what can and can not do?"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/7d6f9ea12efb97a251114fe5255549f1","name":"Peter Verhas","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c4bf0144531172dc8ef1aec04c1faabd409f61d458b3b37ae1dc400b42fbf466?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c4bf0144531172dc8ef1aec04c1faabd409f61d458b3b37ae1dc400b42fbf466?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c4bf0144531172dc8ef1aec04c1faabd409f61d458b3b37ae1dc400b42fbf466?s=96&d=mm&r=g","caption":"Peter Verhas"},"sameAs":["http:\/\/javax0.wordpress.com\/","https:\/\/www.facebook.com\/verhas","http:\/\/www.linkedin.com\/profile\/view?id=674424","https:\/\/x.com\/https:\/\/twitter.com\/verhas"],"url":"https:\/\/www.javacodegeeks.com\/author\/peter-verhas"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/23429","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/539"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=23429"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/23429\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/148"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=23429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=23429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=23429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}