gpt4 book ai didi

oop - Actor 阵容永远不会成功

转载 作者:行者123 更新时间:2023-12-02 12:43:49 24 4
gpt4 key购买 nike

我是Kotlin的新手,目前正在研究OOP的概念

我正在尝试使用此代码进行转换,但是我遇到了一个错误:

open class Operations1(){
open fun sum(n1:Int , n2:Int):Int{
return n1+ n2
}
fun sub(n1:Int , n2:Int):Int{
return n1- n2
}
}
class multiOperations1():Operations(){
override fun sum(n1:Int , n2:Int):Int{
return n1+ n2 +5
}
fun mul(n1:Int , n2:Int):Int{
return n1* n2
}
fun div(n1:Int , n2:Int):Int{
return n1/ n2
}
}
fun main(args:Array<String>){

var oper = Operations()
var inlit = multiOperations1() as Operations1
println("Enter first number")
var n1:Int = readLine()!!.toInt()
println("Enter Second Number")
var n2:Int = readLine()!!.toInt()

var sum = inlit.sum(n1 , n2)
var sub = inlit.sub(n1 , n2)
println("Sum: " + sum)
println("Sub: " + sub)
}

代码的屏幕截图

This is the screen shot of the code

错误:

This is the error which my program through

最佳答案

为此,可以使用Gson并避免样板代码。

var operation= Operations(....)

val json = Gson().toJson(operation)

val multiOperations:MultiOperations =Gson().fromJson(json, MultiOperations::class.java)

关于oop - Actor 阵容永远不会成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45310457/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com