- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
作为一名 Kotlin 编码新手,我想知道是否有一些好的做法甚至语言结构可以在函数中声明前置条件。
在 Java 中,我一直在使用 Guava 的前提条件检查实用程序:
https://github.com/google/guava/wiki/PreconditionsExplained
经过进一步调查,我发现了 require 函数:
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/require.html
这是通常用于检查函数先决条件的方法吗?
最佳答案
当然。您可以在 Preconditions.kt 中找到所有前提条件。 .除了require函数,有requireNotNull , check & checkNotNull功能。
由于文档在 Kotlin 中的描述很差,但您可以看到 Objects#requireNonNull jdk 中的文档作为进一步。
Checks that the specified object reference is not null. This method is designed primarily for doing parameter validation in methods and constructors.
关于kotlin - Kotlin 中的前置条件函数 - 良好实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45131330/
嗨,我正在考虑开发一种文件传输程序,想知道我是否想要尽可能好的加密,我应该使用什么? 我会用 C# 开发它,所以我可以访问 .net 库 :P在我的 usb 上有一个证书来访问服务器是没有问题的,如果
我创建的这个计算两个数组的交集是线性的方法的复杂度(在良好、平均、最差的情况下)? O(n) public void getInt(int[] a,int[] b){ int i=0; int
我已经能够使用 RTCPeerConnection.getStats() API 获得 WebRTC 音频调用的各种统计信息(抖动、RTT、丢包等)。 我需要将整体通话质量评为优秀、良好、一般或差。
基本问题: 如果我正在讲述/修改数据,我应该通过索引硬编码索引访问文件的元素,即 targetFile.getElement(5);通过硬编码标识符(内部翻译成索引),即 target.getElem
在 Linux 上,我想知道要调用什么“C”API 来获取每个 CPU 的统计信息。 我知道并且可以从我的应用程序中读取 /proc/loadavg,但这是系统范围的负载平均值,而不是每个 CPU 的
在客户端浏览器中使用 fetch api,GET 或 POST 没有问题,但 fetch 和 DELETE 有问题。它似乎将 DELETE 请求方法更改为 OPTIONS。 大多数研究表明是一个cor
我是一名优秀的程序员,十分优秀!