Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented class StorageImpl with methods put, get, equals #1664

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

serhii-hl
Copy link

No description provided.

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.

Your implementation of StorageImpl is well-structured and meets the core requirements of the task. 🎉 While there are a few areas for improvement, such as handling the storage limit more gracefully and addressing type safety with generic arrays, these are minor issues that don't significantly impact the functionality. Keep up the great work, and consider these suggestions for future enhancements! 😊

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

private int storageSize = 0;

public StorageImpl() {
keys = (K[]) new Object[MaxStorageSize];

Choose a reason for hiding this comment

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

Casting to a generic array like (K[]) new Object[MaxStorageSize] is not type-safe and can lead to ClassCastException at runtime. Consider using a different approach, such as using an ArrayList or handling the array differently to avoid this issue.


public StorageImpl() {
keys = (K[]) new Object[MaxStorageSize];
values = (V[]) new Object[MaxStorageSize];

Choose a reason for hiding this comment

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

Similar to the keys array, casting to (V[]) new Object[MaxStorageSize] is not type-safe. Consider using a different approach to avoid potential runtime exceptions.

this.values[storageSize] = value;
storageSize++;
} else {
System.out.println("The limit of storage is 10");

Choose a reason for hiding this comment

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

Printing a message to the console is not the best way to handle the situation when the storage limit is reached. Consider throwing an exception or using a logging framework to handle this scenario more gracefully.

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