Extracting info

Report a typo

Define and implement a generic method info inside the companion object Info that accepts a generic list and returns the contents of the input list as a String. If the list is empty, return "[]". You do not need to print the result.

A companion object is an object declared inside a class which allows you to store common properties or use common methods of this class. You can learn more about it here or in our topic.

Below you can see the parameter names and types the function accepts and its result type.

Input:

list: List<T>

Output:

String

Example input

listOf(1, 2, 3, 4, 5)

Example output

[1, 2, 3, 4, 5]

Write a program in Kotlin
class ListUtils {
companion object Info {

// define info method here

}
}
___

Create a free account to access the full topic