কম্পিউটার টিউটোরিয়াল

জাভাতে IntUnaryOperator ইন্টারফেস


জাভাতে ফাংশনাল প্রোগ্রামিং-এর জন্য, জাভা ৯ ভার্সন IntUnaryOperator নিয়ে এসেছে। একটি উদাহরণ নিচে দেখানো হলো:

উদাহরণ

import java.util.function.IntUnaryOperator; public class Demo{    public static void main(String args[]){       IntUnaryOperator op_1 = IntUnaryOperator.identity();       System.out.println("The identity function :");       System.out.println(op_1.applyAsInt(56));       IntUnaryOperator op_2 = a -> 3 * a;       System.out.println("The applyAsInt function :");       System.out.println(op_2.applyAsInt(56));       IntUnaryOperator op_3 = a -> 3 * a;       System.out.println("The andThen function :");       op_3 = op_3.andThen(a -> 5 * a);       System.out.println(op_3.applyAsInt(56));       IntUnaryOperator op_4 = a -> a / 6;       System.out.println("The compose function :");       op_4 = op_4.compose(a -> a * 9);       System.out.println(op_4.applyAsInt(56));    } }

আউটপুট

The identity function : 56 The applyAsInt function : 168 The andThen function : 840 The compose function : 84

'Demo' নামক একটি ক্লাসে main ফাংশন আছে। এখানে, 'identity' ফাংশনটি 'IntUnaryOperator'-এর একটি ইনস্ট্যান্সের ওপর ব্যবহার করা হয়েছে। একইভাবে, অন্যান্য ফাংশন যেন 'applyAsInt', 'andThen', এবং 'compose' ফাংশনগুলো 'IntUnaryOperator'-এর নতুন তৈরি করা ইনস্ট্যান্সের সাথে ব্যবহার করা হয়েছে। প্রতিটি ফাংশন কলের আউটপুট যথাক্রমে কনসোলে প্রিন্ট করা হয়েছে।

  1. জাভাতে একটি ইন্টারফেস অন্য ইন্টারফেস ইমপ্লিমেন্ট কেন করতে পারে না?

  2. জাভাতে নেস্টেড ইন্টারফেস

  3. জাভা ৮-এ ইন্টারফেস এনহ্যান্সমেন্ট

  4. জাভাতে ইন্টারফেস