kotlin エラー「error: this type has a constructor, and thus must be initialized here」の解決方法

kotlinで、エラー「error: this type has a constructor, and thus must be initialized here」の解決方法を記述してます。
環境
- OS windows11 home
- java 19.0.1
- kotlin 1.7.20-release-201
エラー全文
以下のコードで発生。
abstract class Hoge {
abstract fun f()
}
class Foo() : Hoge {
override fun f() { println("Foo") }
}
fun main(){
val bar = Foo()
bar.f() // Foo
}
エラーメッセージ
error: this type has a constructor, and thus must be initialized here
class Foo() : Hoge {
^
原因
「サブクラス」で使用する「抽象クラス」に「()」を使用していないため
対処法
「()」を使用する
abstract class Hoge {
abstract fun f()
}
class Foo() : Hoge {
override fun f() { println("Foo") }
}
fun main(){
val bar = Foo()
bar.f() // Foo
}
-
前の記事
Oracle Database 全てのディレクトリ情報を一覧で取得する 2023.02.10
-
次の記事
PostgreSQL 指定したデータで配列を生成する 2023.02.10
コメントを書く