Exercise4/src/main/kotlin/de/hpi/dbs1/ChosenImplementation.kt
2025-06-13 17:01:40 +02:00

23 lines
698 B
Kotlin

package de.hpi.dbs1
import JDBCExerciseJavaImplementation
import JDBCExerciseKotlinImplementation
annotation class ChosenImplementation(
val value: Boolean
)
class NoSubmissionImplementationChosen : IllegalStateException(
"Chose an implementation for your exercise by setting @ChosenImplementation(true)"
)
fun getChosenImplementation(): JDBCExercise {
return listOf(
JDBCExerciseJavaImplementation::class.java,
JDBCExerciseKotlinImplementation::class.java,
).firstOrNull { clazz ->
clazz.getAnnotation(ChosenImplementation::class.java)?.value ?: false
}?.getDeclaredConstructor()?.newInstance()
?: throw NoSubmissionImplementationChosen()
}