Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to achieve java laziness Assessment

Shulou Source: shulou.com Published: 2022-05-31 10:48:18 09月20日 Update

This article mainly introduces the java laziness assessment of how to achieve the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this java laziness assessment how to achieve the article will have a harvest, let's take a look.

Description

1. Lazy evaluation is the process of delaying the evaluation of expressions until they are needed. Java is a strict immediate assignment evaluation.

2. It can be rewritten as a version of deferred evaluation using lambda expressions and higher-order functions.

Example

Public class LazySample {public static void main (String [] args) {/ / this is a lambda expression, represented by the closure UnaryOperator add = t-> {System.out.println ("executing add"); return t + t;}; / / this is an lambda expression, represented by the closure UnaryOperator multiply = t-> {System.out.println ("executing multiply") Return t * t;}; / / pass Lambda closures instead of ordinary functions System.out.println (addOrMultiply (true, add, multiply, 4); System.out.println (addOrMultiply (false, add, multiply, 4)) } / / this is a higher order function static R addOrMultiply (boolean add, Function onAdd, Function onMultiply, T t) {/ / Java? Will be lazy to evaluate expressions, so only execute the required method return (add? OnAdd.apply (t): onMultiply.apply (t);}} this is the end of the article on "how to achieve java laziness Assessment". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to achieve java laziness assessment". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Tags: Evaluation laziness expression function knowledge this is closure content article high-order delay ordinary value instance inertia simple operation article method easy to understand more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MariaDB Linux Redmi OPPO Reno