简体   繁体   English

Kotlin REPL 算法

[英]Kotlin REPL Arithmetic

I just got started with a book on Kotlin and guess what?我刚开始读一本关于 Kotlin 的书,你猜怎么着? yes I can't figure out anything.是的,我什么也想不通。 Here is the thing just by using REPL you can run part of your code and see if it runs without the need of creating a new file but I got a beautiful error message when I try to do min (43, -33), or any min(), max() and so on.这是仅通过使用 REPL 您可以运行部分代码并查看它是否在不需要创建新文件的情况下运行的事情但是当我尝试执行 min (43, -33) 或任何min(), max() 等等。

here is the error examples:这是错误示例:

max(22, 33) error: unresolved reference. max(22, 33)错误:未解析的引用。 None of the following candidates is applicable because of receiver type mismatch:由于接收器类型不匹配,以下候选都不适用:

min(93, -99) error: unresolved reference. min(93, -99)错误:未解析的引用。 None of the following candidates is applicable because of receiver type mismatch: public fun <T : Comparable<TypeVariable(T)>> Array<out TypeVariable(T)>.min(): TypeVariable(T)?由于接收器类型不匹配,以下候选都不适用: public fun <T : Comparable<TypeVariable(T)>> Array<out TypeVariable(T)>.min(): TypeVariable(T)? defined in kotlin.collections public fun Array.min(): Double?在 kotlin.collections 中定义 public fun Array.min(): Double? defined in kotlin.collections在 kotlin.collections 中定义

Thanks to all and appreciate any help!!!感谢所有人并感谢任何帮助!!!

The min() and max() funtions are not part of the core language, the are defined in the standard library in the kotlin.math package. min()max()函数不是核心语言的一部分,它们是在kotlin.math包的标准库中定义的。 You need to import the package, than you can use these methods:您需要导入包,然后才能使用这些方法:

import kotlin.math.*
min(22, 33)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM