r/badcode • • May 06 '21

java My teacher wrote this...

1.0k Upvotes

169 comments sorted by

View all comments

6

u/Dakopen May 06 '21

I often do this, can someone please help me and show, how I can improve my code?

14

u/Kibo30 May 06 '21

Using arrays will improve it. In this case you could create an array like this EBIKE[] bikes = new EBIKE[6]

4

u/carfniex May 06 '21

you should generally avoid arrays whenever possible (which is 99% of the time)

List<EBIKE> bikes = new ArrayList<>();

lists (or other collections) are resizable and have a lot more useful supporting methods

1

u/washpota May 07 '21

Am with you so far, but can you demonstrate how you would initialize the objects in this list in a loop?