如何从Kotlin中返回对象的函数获取值

时间:2019-04-03 16:33:53

标签: kotlin

我正在使用数学通用库,但事实证明,当我想要一个函数返回Double 时,intellij的想法会自动将其更正为对象。

int SudokuSolver::rowUniques() {
    int count = 0;
    vector<int> rowVec(_maximumDim); // Specify maximum dimension       
    for (int row = 0; row < _dim; row++) {
        for (int i = 0; i < _dim; i++) {
            rowVec[i] = _sudoku[i][row];
        }
        for (int i = 1; i <= _dim; i++) {
            if (isUnique(rowVec, i)) {
                count++;
            }
        }
    }
    return count;
}

退回

import org.apache.commons.math3.distribution.TDistribution


// TDistribution  --> It doesn't allow me to change to Double
fun calculo(a:Double): TDistribution {

    val distf = TDistribution(28.0,a)
    return distf
}

fun main(args: Array<String>){

    val ko = calculo(0.95)
    println(ko)
}

1 个答案:

答案 0 :(得分:1)

您的函数返回TDistribution。要返回Double,您需要这样的东西:

fun calculo(a:Double): Double {
    val distf = TDistribution(28.0,a)
    return distf.getNumericalMean()
}

fun main(args: Array<String>) {
    val ko = calculo(0.95)
    println(ko)
}