Functional Interface in java 8

خرید بک لینک

Functional Interface in java 8  به زبان ساده

1. BiConsumer:

Retus a composed BiConsumer that performs,
in sequence,this operation followed by the after operation.
If performing either peration throws an exception,
it is relayed to the caller of the composed operation.
If performing this operation throws an exception, the after operation will not be performed.
Params: after – the operation to perform after this operation
Retus:a composed BiConsumer that performs in sequence this operation followed by the after operation

بعنوان ورودی دو عملیات میگیرد،

اگر اجرای هر یک از عملیات ها خطاایجاد کند،

به تماس گیرنده عملیات تشکیل شده منتقل می شود.

اگر انجام عملیات اولی استثناء (خطا ) ایجاد کند، عملیات after انجام نخواهد شد.

Retus: یک BiConsumer تشکیل شده که این عملیات را به ترتیب انجام می دهد و سپس عملیات بعد را انجام می دهد.

2.Predicate :

یک گزاره (تابع با مقدار بولی) یک آرگومان را نشان می دهد.
این یک رابط کاربردی است که روش کاربردی آن test (Object) است.
نوع پارامترها:
- نوع ورودی به Predicate

3.Unary Operator:

The java.util.function.UnaryOperation interface in Java represents an operation. This operation takes a single parameter and retus a parameter of the same type.

Below is the example of a Java UnaryOperator implementation

یک عملیات را نشان می دهد. این عملیات یک پارامتر واحد را می گیرد و یک پارامتر از همان نوع را برمی گرداند.

در زیر مثالی از اجرای Java UnaryOperator آورده شده است:

UnaryOperator  Person > unaryOperator = (person) - >{  person.name = "New Name";  retu person;};

4.BinaryOperator

The Java BinaryOperator interface is useful when there is a need to implement functions like
sum, subtract, divide, multiply, etc., that have two elements of the same type, and retu a third element of the same type.

رابط Java BinaryOperator زمانی مفید است که نیاز به اجرای توابعی مانند توابع زیر وجود داشته باشد
جمع، تفریق، تقسیم، ضرب و غیره که دو عنصر از یک نوع دارند و عنصر سومی از همان نوع را برمی گرداند.

 

BinaryOperator  MyValue > binaryOperator = (value1, value2) - >{  value1.add(value2);  retu value1;};

 

5.Supplier

The Supplier interface of Java is a functional interface that represents a function that supplies a value of some sort. This interface can also be thought of as a factory interface.

Below is an example of implementation of the Java Supplier interface:

رابطSupplier جاوا یک رابط کاربردی است که عملکردی را نشان می دهد که مقداری را ارائه می دهد. این رابط را می توان به عنوان یک رابط کارخانه نیز در نظر گرفت.

در زیر نمونه ای از پیاده سازی رابط جاوا Supplier آورده شده است:

Supplier Integer > supplier = () - >new Integer((int)(Math.random() * 1000D));

+ نوشته شده در 2022/3/29 ساعت 11:21 توسط علیرضاابوالحسنی  | 

هم میهنان کورد زبانم تسلیت......

ما را در سایت هم میهنان کورد زبانم تسلیت... دنبال می‌کنید

برچسب: نویسنده: بازدید: 144 تاريخ: يکشنبه 19 تير 1401 ساعت: 6:47

صفحه بندی