Get the App
SLTechnology News&Howtos  ›  Development  › 

How Java defines the output of Holder class implementation parameters

Shulou Source: shulou.com Published: 2022-06-01 06:16:07 09月10日 Update

This article mainly introduces Java how to define the output of Holder class implementation parameters, the article is very detailed, has a certain reference value, interested friends must read it!

Define the output of Holder class implementation parameters

In many languages, the parameters of a function can be divided into input (in), out (output) and input output (inout). The reference of object (&) can be used to realize the output (out) and input output (inout) of function parameters in C _ language _. However, in the Java language, although there is no similar function of object reference, the output (out) and input output (inout) of function parameters can be realized by modifying the field values of parameters. Here, we call the data structure corresponding to this output parameter the Holder class.

The Holder class implementation code:

/ * * long integer support class * / @ Getter@Setter@ToStringpublic class LongHolder {/ * long integer value * / private long value; / * * constructor * / public LongHolder () {} / * * constructor * / public LongHolder (long value) {this.value = value;}

Holder class use case:

/ * * static constants * / / * * number of pages * / private static final int PAGE_COUNT = 100 pageIndex * maximum * / private static final int MAX_COUNT = 1000 * handle overdue orders * / public void handleExpiredOrder () {LongHolder minIdHolder = new LongHolder (0L); for (int pageIndex = 0; pageIndex)

< PAGE_COUNT; pageIndex++) { if (!handleExpiredOrder(pageIndex, minIdHolder)) { break; } }}/** 处理过期订单 */private boolean handleExpiredOrder(int pageIndex, LongHolder minIdHolder) { // 获取最小标识 Long minId = minIdHolder.getValue(); // 查询过期订单(按id从小到大排序) List orderList = orderDAO.queryExpired(minId, MAX_COUNT); if (CollectionUtils.isEmpty(taskTagList)) { return false; } // 设置最小标识 int orderSize = orderList.size(); minId = orderList.get(orderSize - 1).getId(); minIdHolder.setValue(minId); // 依次处理订单 for (OrderDO order : orderList) { ... } // 判断还有订单 return orderSize >

= PAGE_SIZE;}

In fact, you can implement a generic support class that is suitable for more data types.

This is all the content of the article "how Java defines the output of Holder class implementation parameters". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Output parameters functions orders input language processing minimum content object data quantity more logo article maximum from small to big from small code value Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Apple OPPO Reno Docker Shulou Tech Info