publicfun <T> List<T>.single(): T {returnwhen (size) {0->throwNoSuchElementException("List is empty.")1->this[0]else->throwIllegalArgumentException("List has more than one element.") }}val list =listOf(1, 2, 3, 4, 5)val singleList =listOf(1)val emptyList =listOf<Int>()println(list.single()) // Errorprintln(singleList.single()) // 1println(emptyList.single()) // Error