3
我有科特林代碼,其中所述第一和第二構造的不同微小片斷,參見下文科特林 - 次要的構造,通過一個參數不同
class InstructionPrototype constructor(
val iname: String,
val opcode: Int,
val mnemonicExample: String,
val numericExample: Int,
val description: String,
val format: Format,
val pattern: Pattern,
var type: Type? = null,
var rt: Int? = null,
var funct: Int? = null,
var conditions: Array<(n: Int) -> String?>? = null) {
constructor(
iname: String,
opcode: Int,
mnemonicExample: String,
numericExample: Int,
description: String,
format: Format,
pattern: Pattern,
type: Type?,
rt: Int?,
funct: Int?,
condition: (n: Int) -> String?
): this(iname, opcode, mnemonicExample, numericExample, description,
format, pattern, type, rt, funct, arrayOf(condition)) {
}
是有可能通過一些語言來減少這種冗長構造?我正在考慮代數數據類型,但這並不是一個好的選擇 - 它被認爲是「hacky」。