• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

default methods

 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some how I don't seem to like the default methods introduced in Java 8. When I started to learn Java interface had no implementation but no they have methods. Didn't Java API designers have any other means to introduce streaming for collections. Can the authors of Java 8 share their opinion. Also do default method support method overloading and overriding.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried to overload or override a default method?
How else are you going to add Streams to the List interface without breaking every implementation which does not extend AbstractList?
 
author
Posts: 84
5
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pradeep,

The addition of default methods is a controversial one for many. Time will tell, however, I feel they are a good addition. I don’t have much insight into the developer’s rationale. Maurice Naftalin’s comments are a good starting point for further information about this topic: http://www.lambdafaq.org/what-are-default-methods/.

 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I gave a presentation today on Java 8 interfaces and Dates. I made a comment that "if you add a default method to new code, you are doing something wrong." I think the use of adding functional type methods to collections is a good one.
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I understand this is the only way to add code to List interface but it looks odd.

Jeanne Boyarsky wrote:I gave a presentation today on Java 8 interfaces and Dates. I made a comment that "if you add a default method to new code, you are doing something wrong." I think the use of adding functional type methods to collections is a good one.



That is a good point. If we need to add a default method then may be it should be an abstract class.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, adding the default method to the abstract class will not always work; some classes will implement the interface without extending that abstract class. And it wouldn't be a default method in an abstract class; it wouild be a pain simple concrete method, probably designed so as to be overridden.
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:No, adding the default method to the abstract class will not always work; some classes will implement the interface without extending that abstract class. And it wouldn't be a default method in an abstract class; it wouild be a pain simple concrete method, probably designed so as to be overridden.



what I meant was if someone is planning to create a new interface with a default method they can very well create an abstract class with a common method. Anway you have made a very good point that method can be overriden.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you can, but you can't both create a new interface and a new abstract class unless they both have the method.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, not in that situation anyway.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic