ghazalghorabi / TDA553-lab1

0 stars 0 forks source link

CRITICAL: Instance variables must be initialized by end of constructor (either in constructor or in declaration) #24

Closed martinjonsson01 closed 1 year ago

martinjonsson01 commented 1 year ago

platform and loadedCars are never instantiated, so they will remain null. carAmount is not initialized either, so it will default to 0. It's important that an object is left in a valid state after construction. If you leave some instance variables null after construction, then a method could call these instance variables without knowing they're null, which results in a NullPointerException.

https://github.com/ghazalghorabi/TDA553-lab1/blob/01f3360df2ab6d8a3dae4522fac81312009bb5d9/src/CarTransporter.java#L6-L16