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 annotations Inject and Component #1019

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

StoneBlood-bit
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.

Great job on implementing the task requirements! While there are some minor improvements suggested, they don't impact the core functionality. Keep up the good work and consider the feedback for future enhancements! 🚀

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

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)

Choose a reason for hiding this comment

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

You should add @Target to the @Component annotation as per the checklist requirement: 'Do not forget to add @Target to custom annotations.'

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)

Choose a reason for hiding this comment

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

You forgot to add @Target to the @Inject annotation. According to the checklist, it is necessary to specify the target for custom annotations.

public class Injector {
private static final Injector injector = new Injector();
private Map<Class<?>, Object> instances = new HashMap<>();

Choose a reason for hiding this comment

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

It is recommended to make the Interface Implementations map a class field and fill it using Map.of() as per the checklist.

Comment on lines +27 to +28
throw new RuntimeException("No implementation found for interface: "
+ interfaceClazz.getName());

Choose a reason for hiding this comment

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

When throwing an exception, add an informative message to it. Also, don't forget to add the exception you're catching in the catch block to the RuntimeException object you throw.

Comment on lines +49 to +50
throw new RuntimeException("Can't initialize field value. Class: "
+ clazz.getName() + ". Field: " + field.getName());

Choose a reason for hiding this comment

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

When throwing an exception, add the caught exception to the RuntimeException object you throw to provide more context.

Comment on lines +72 to +73
} catch (NoSuchMethodException | InvocationTargetException
| InstantiationException | IllegalAccessException e) {

Choose a reason for hiding this comment

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

It is better to replace many exceptions that have a common parent with a general parental exception, such as ReflectiveOperationException.

return instance;
} catch (NoSuchMethodException | InvocationTargetException
| InstantiationException | IllegalAccessException e) {
throw new RuntimeException("Can't create a new instance of " + clazz.getName());

Choose a reason for hiding this comment

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

When throwing an exception, add the caught exception to the RuntimeException object you throw to provide more context.

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