Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Extra things with Functional Interface  RSS feed

 
Ranch Hand
Posts: 60
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: 8889
166
  • 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: 60
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: 60
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: 8889
166
  • 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
 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!