1005 B
Extension Lambdas (#1)
Define the following functions so they behave the same as their standard library counterparts:
-
createString()
behaves likebuildString()
. Start by creating a new instance ofStringBuilder
, call the extension lambda argument on it, then return theString
result. -
createList()
behaves likebuildList()
. This function has one generic parameter. Create anArrayList<T>
, call the extension lambda argument on it, and return a read-onlyList
. -
createMap()
behaves likebuildMap()
. This function has two generic parameters. Create aHashMap<K, V>
, call the extension lambda argument on it, and return a read-onlyMap
.
The code in main()
tests your functions against the standard library
versions. Notice that buildList()
and buildMap()
infer their generic
parameters.
This task doesn't contain automatic tests, so it's always marked as "Correct" when you run "Check". Please compare your solution with the one provided!