This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Extra things with Functional Interface  RSS feed

 
Ranch Hand
Posts: 71
2
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have written code for functional interface, which retrieve the first and last occurrences from string. Here is the code:


LongString and StringOp are functional interfaces here, even though StringOp not declared as Single Abstract Method as itself. By inheriting it, StringOp supported another functional interface concept.

However, Object class provided the valid overridden methods.

Default/static method also presented to the additional operation as well.

It then implemented with lambda expressions for string operation.
Output is shown:
First: Java
Last: language!
Intermedia: is

My comment is to this situation:
It shall only fulfill/declare functional interface through inheritance.

Like final variable, it doesn't.

Thank you for your comments/discussion on this thread.


 
Saloon Keeper
Posts: 9707
192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what is special about this situation. A functional interface is any interface, whether it extends another interface or not, that only requires an implementing class to implement exactly one method.
 
Noorul Hameed
Ranch Hand
Posts: 71
2
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:I'm not sure what is special about this situation. ...



Hi Mr. Stephen,

Single Abstract Method for Functional Interface concept is required at any case. The  definition of such method, inheritance or overriding is to facilitate functional. Rule is to execute it.

So it uniquely identifies the function at last too.


Thanks.
 
author
Posts: 200
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I understand either.

A functional interface must have one abstract method.
 
Noorul Hameed
Ranch Hand
Posts: 71
2
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Elisabeth Robson wrote:I'm not sure I understand either.
A functional interface must have....



Yes sir, it is definitely true condition.

A bit more clear explanation is Sum interface contained only one abstract T getSum(T a, T b), as written in below code. Two types of implementations are: interface to object; and functional interface to lambda
 
Stephan van Hulst
Saloon Keeper
Posts: 9707
192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no real difference. The results of evaluating a lambda expression is an object of an anonymous type that implements the interface.

Whether you create an implementation of a functional interface through a lambda expression, an anonymous class instantiation or a normal class instantiation... it's all the same.
 
Elisabeth Robson
author
Posts: 200
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, think of lambda as a short hand for a class that implements a functional interface
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!