-
Notifications
You must be signed in to change notification settings - Fork 222
Open
Labels
Description
- If our application needs a Map of Sensors, you might find the sensors set up like this:
java Map sensors = new HashMap(); - Then, when some other part of the code needs to access the sensor, you see this code:
java Sensor s = (Sensor)sensors.get(sensorId ); - This works, but it’s not clean code. Also, this code does not tell its story as well as it
could. - The readability of this code can be greatly improved by using generics, as shown
below:
Map<Sensor> sensors = new HashMap<Sensor>();
...
Sensor s = sensors.get(sensorId );```