• 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
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Extra things with Functional Interface  RSS feed

 
Ranch Hand
Posts: 70
1
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: 9401
181
  • 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: 70
1
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
Ranch Hand
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: 70
1
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: 9401
181
  • 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
Ranch Hand
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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!