Skip to content

Conversation

serhii-hl
Copy link

…realised method main

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job following the checklist guidelines in your Application.java file! 🎉 Your code is functional and meets the core requirements. Just a couple of suggestions for the future: try using name() for enums to get their string representation as it's safer in case toString() gets overridden, and consider reusing a single Random instance for efficiency. Keep up the good work! 👍

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

public class ColorSupplier {
public String getRandomColor() {
return null;
int index = new Random().nextInt(DifferentColors.values().length);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a new instance of Random for every method call is inefficient. Consider creating a single Random instance as a class field and reusing it.

return null;
int index = new Random().nextInt(DifferentColors.values().length);
DifferentColors ballColor = DifferentColors.values()[index];
return ballColor.toString();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using toString(), it's better to use name() for getting the String representation of enum constants to avoid issues if toString() is overridden.

@serhii-hl serhii-hl closed this Aug 15, 2024
@serhii-hl serhii-hl reopened this Aug 16, 2024
@serhii-hl serhii-hl closed this Aug 16, 2024
@serhii-hl serhii-hl reopened this Sep 10, 2024
@serhii-hl serhii-hl closed this Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants