Dominick
03/31/2021, 4:01 AMval commands: MutableSet<Command<JDACommandSender>> = mutableSetOf()
get() = Collections.unmodifiableSet(field)
My goal is to allow the class itself to modify commands
directly, but others to only be able to get an unmodifiable version of the contents. Is there any direct way to achieve this?nanodeath
03/31/2021, 4:07 AMnanodeath
03/31/2021, 4:08 AMprivate val privateCommands = mutableSetOf<Command>()
val commands get() = Collections.unmodifiableSet(privateCommands)
// or
val commands get() = Collections.unmodifiableSet(privateCommands.toSet())
nanodeath
03/31/2021, 4:09 AMval commands = persistentSetOf<Command>()
private set
Dominick
03/31/2021, 4:11 AMDominick
03/31/2021, 4:17 AMprivate set
and val
because val cannot be reassigned. Should it be var
or should private set be removed?nanodeath
03/31/2021, 4:17 AMnanodeath
03/31/2021, 4:19 AMDominick
03/31/2021, 4:22 AM