小编Nee*_*eeK的帖子

android 配对命令未找到(无线调试)

我正在尝试使用以下方法无线连接到我的手机进行 USB 调试:

adb pair 192.168.30.27:41424

但我收到以下错误:

"Unknown command pair" error.

我已经将 Android SDK Platform 工具更新到 31+ 版本,但这仍然不能解决此问题。

android adb adbwireless

22
推荐指数
2
解决办法
3万
查看次数

如何在 Kotlin 中将 MutableList<Int> 转换为 IntArray?

我想将 MutableList 转换为 IntArray。我正在使用 toTypedArray() 进行转换,但它导致异常:

Line 15: Char 23: error: type inference failed. Expected type mismatch: inferred type is Array<Int> but IntArray was expected
        return result.toTypedArray()
                  ^ 
Run Code Online (Sandbox Code Playgroud)

以下是完整代码:

fun intersection(nums1: IntArray, nums2: IntArray): IntArray {
            val set: MutableSet<Int> = mutableSetOf()
            val result: MutableList<Int> = mutableListOf()

            for(num in nums1) set.add(num)

            for(num in nums2) {
                if(set.contains(num)) {
                    result.add(num)
                    set.remove(num)
                }
            }

            return result.toTypedArray()
        }
Run Code Online (Sandbox Code Playgroud)

kotlin

5
推荐指数
1
解决办法
3294
查看次数

打印 IntArray 内容的 Kotlin 方式是什么?

打印 IntArray 内容的 Kotlin 方式是什么?

class Solution {
    fun plusOne(digits: IntArray): IntArray {

        println(digits.toString()) // does not work
        println(Arrays.toString(digits)) // does work but its java way of doing
        for(i in 0 until digits.size) {
           ...
        }

        return digits
    }
}
Run Code Online (Sandbox Code Playgroud)

有没有类似于 Arrays.toString() 的 kotlin 方法?我只想查看用于调试目的的内容。

kotlin

5
推荐指数
3
解决办法
262
查看次数

在 Kotlin 中使用索引迭代 IntArray 的最佳方法

我正在寻找一种最好的方法来迭代 IntArray 索引类似于下面的 JAVA 代码

for (int i = 0; i < arr.length - 1; i++)
Run Code Online (Sandbox Code Playgroud)

我正在使用下面的代码,我不想迭代最后一个元素来避免IndexOutOfBoundException. A.indices允许我迭代所有索引,而我不想像上面那样触摸最后一个元素:

class Solution {
    fun isMonotonic(A: IntArray): Boolean {
        var increasing : Boolean = false
        var decreasing : Boolean = false

        for (i in A.indices) {
            if (A[i] <= A[i+1]) increasing = true
            if (A[i] >= A[i+1]) decreasing = true
        }

        return increasing && decreasing
    }
}
Run Code Online (Sandbox Code Playgroud)

functional-programming kotlin

3
推荐指数
1
解决办法
650
查看次数

为什么我们不在 Kotlin 的类中编写 main() ?

为什么 kotlin 不允许像 Java 一样在类中使用 main() 函数?为什么允许在课堂外这样做?这不是违背了OOP原则吗?我很疑惑!

class Person ( var name : String, var age : Int) {
    // putting main here
    fun main(args : Array<String>) {
        val person = Person("Neek", 34)
        println("my name is ${person.name}")
        println("my name is ${person.age}")
    }
}
Run Code Online (Sandbox Code Playgroud)

尝试在类中包含 main() ,我收到以下错误。

warning: parameter 'args' is never used
    fun main(args : Array<String>) {
no main manifest attribute
Run Code Online (Sandbox Code Playgroud)

kotlin

2
推荐指数
2
解决办法
6235
查看次数