I am storing shared preferences value as a HashSet
and when retrieving I see the warning about unchecked casting. What is the most simple and what is the safest solution to ensure bug free implementation here?
class TaskListDataManager(private val context: Context) {
fun saveList(taskList: TaskList) {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context).edit()
sharedPreferences.putStringSet(taskList.name, taskList.taskList.toHashSet())
sharedPreferences.apply()
}
fun readList(): ArrayList<TaskList> {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
val taskLists = sharedPreferences.all.map {
TaskList(it.key, ArrayList(it.value as HashSet<String>))
}
return ArrayList<TaskList>(taskLists)
}
}