gpt4 book ai didi

scala - 向 Scala 的构造函数添加自定义逻辑

转载 作者:行者123 更新时间:2023-12-01 04:52:07 25 4
gpt4 key购买 nike

假设我有一个类

  class MyClass(a: Int, b: String) {
//....
}

如果我想向这个构造函数添加一些自定义逻辑(代码),我该怎么做?

最佳答案

class MyClass(a: Int, b: String) {
// this is the constructor right here
println("Hi, i'm the constructor")

def imAMethod = 1

println("Hi, I'm also part of the constructor down here, the whole class body is")
}

关于scala - 向 Scala 的构造函数添加自定义逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16909344/

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