Skip to content

Lab2 Solution#6

Open
Artikhog wants to merge 3 commits intomasterfrom
master
Open

Lab2 Solution#6
Artikhog wants to merge 3 commits intomasterfrom
master

Conversation

@Artikhog
Copy link

No description provided.

return traverseClassHierarchy(clazz, annotation);
}

private static Optional<Class<?>> traverseClassHierarchy(
Copy link

Choose a reason for hiding this comment

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

А зачем вот эта штука хитрая (имею ввиду обход такой)?

Copy link
Author

Choose a reason for hiding this comment

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

если переданный класс не аннотирован, то метод ищет аннотированный класс выше по иерархии классов

public class PackageUtils {
public static Optional<Class<?>> getAnnotatedClass(
final Class<?> targetClass,
final Class<? extends Annotation> annotation,
Copy link

Choose a reason for hiding this comment

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

Ваще по смыслу аннотация всегда она и та же, но можно и так

InstantiationException,
IllegalAccessException
{
var annotatedClass = getAnnotatedClass(clazz, Generatable.class, packageName);
Copy link

Choose a reason for hiding this comment

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

Кажется вы забыли тестики. В связи с этим вопрос -- а если я на вход вашему главному методу дам коллекцию какую нибудь типа списка, оно будет работать?

Copy link

Choose a reason for hiding this comment

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

Хотя по условиям этого особо не требуется конечно

Copy link
Author

Choose a reason for hiding this comment

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

Если коллекция не помечена аннотацией, то главный метод выбросит исключение. Если коллекция помечена аннотацией, то метод просто создаст пустую коллекцию

}

}
field.set(instance, value);
Copy link

Choose a reason for hiding this comment

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

а если оно статик? нет ли нюансов с остальными модификаторами?

Copy link
Author

Choose a reason for hiding this comment

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

да, это может привести к ошибкам. добавил исключение изменения статических полей в коде выше

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

Comments