Looking to implement a map of key value pairs in Kotlin inside a class that is mutable and can be updated and referenced as needed. Research suggests that using a MutableMap would be the appropriate choice, given its ability to be updated at any point. In TypeScript, the code for this scenario would resemble the example below. How might one achieve similar functionality in Kotlin?
type Callback = (id: string) => void | null;
interface DataMap {
streetNumber: number | null;
streetName: string | null;
callback: Callback | null;
}
const dataMap: DataMap = {
streetNumber: null,
streetName: null,
callback: null,
}
// perform an action later..
const doSomething = (streetName: string, callback: Callback): void => {
dataMap.streetName = streetName;
dataMap.callback = callback;
}
// followed by..
const printData = (): void => {
console.log(dataMap.streetName) // prints the streetName
}