Objects and class objects cannot be converted?

I don’t want to muck up the page, so there will be a pastebin at the bottom with my code on it.

I am trying to create a HashMap and create multiple objects of a ‘Car’ class depending on the variable entered into my ‘Traffic’ class. But I get an error on line 28 saying “Type mismatch: cannot convert to Object to traffic.Car.” How do I solve this issue?

Traffic class: https://pastebin.com/yyFsnEhn
Car class: https://pastebin.com/pUq8rLMg

1 Like

Replace private Map cars = new HashMap();
w/ final Map<String,Car> cars = new HashMap<String,Car>();

1 Like

Thanks! I am trying to make it so that the quantity of the Car objects are controlled by a single variable from the traffic class.

FYI, you can embed code blocks of any length, and they will become scrollable and syntax highlighted as long as you format your code.

1 Like