Scrivio Interview library

Annotations

22 questions in 7 subtopics.

Built-in annotations

ConceptFoundations6 min read
What do @Override, @Deprecated, @SuppressWarnings, @FunctionalInterface and @SafeVarargs each do, and which of them change what the compiler does?
DebuggingFoundations5 min read
A developer writes public boolean equals(Order other) in class Order and adds no annotation. HashSet<Order> still contains duplicates. What is wrong and how would @Override have helped?
ScenarioIntermediate6 min read
Your team owns a shared library and needs to remove a public method used by about 40 services. How do you use @Deprecated and related tooling to retire it safely?

Meta-annotations

ConceptFoundations6 min read
What are meta-annotations? Explain @Retention, @Target, @Documented, @Inherited and @Repeatable.
InternalsIntermediate5 min read
Spring lets you write @RestController instead of @Controller plus @ResponseBody, and @GetMapping instead of @RequestMapping(method = GET). Java annotations cannot extend each other. How does this composition work?
DesignAdvanced6 min read
You are defining a set of composed annotations for your organisation's Spring starter, for example @InternalApi combining security, validation and transaction settings. What rules do you set so they stay understandable and safe?

Retention policies and targets

ConceptFoundations5 min read
Explain RetentionPolicy.SOURCE, CLASS and RUNTIME with one real example of each. Which is the default when @Retention is missing?
DebuggingFoundations5 min read
A custom annotation is declared as @interface Audited {} and placed on service methods. An aspect checks method.isAnnotationPresent(Audited.class) and it always returns false. Why?
ConceptIntermediate6 min read
What do ElementType.TYPE_PARAMETER, TYPE_USE, MODULE and RECORD_COMPONENT targets allow, and what happens when an annotation on a record component has several targets such as FIELD and METHOD?

Custom annotations

CodingFoundations6 min read
Write a custom annotation @Retry(times = 3) usable only on methods and readable at run time, and a small reflective helper that calls a method again on exception up to the configured count.
DesignIntermediate7 min read
A team proposes a custom annotation @Cacheable-like @Memoize that a library processes at run time with reflection on every call. Review this design: what are the costs and the alternatives?
LeadershipAdvanced6 min read
Teams in your organisation keep inventing custom annotations that trigger hidden behaviour at run time. Developers complain that code is hard to follow. What guidelines would you set?
LeadershipPrincipal7 min read
Over twenty years Java frameworks moved from XML configuration to annotations and now partly toward explicit Java configuration and build-time processing. What does that history teach about where configuration should live, and what would you standardise for the next decade?

Annotation processing at compile time

InternalsIntermediate6 min read
How does a JSR 269 annotation processor work? Describe the rounds, what a processor can read, and what it can and cannot change.
CodingIntermediate7 min read
Outline an annotation processor that generates a Builder class for every class annotated @GenerateBuilder. Show the key methods you would override and how you would write the output.
ScenarioAdvanced7 min read
Your platform relies on Lombok across 300 services. A new JDK release breaks Lombok for a few weeks after release. How do you assess and manage the risk, and would you change course?
LeadershipPrincipal7 min read
Looking back, why did Java choose annotation processing that can only generate new files rather than macros that rewrite code? What does that mean for your long-term choice between compile-time code generation and run-time reflection frameworks?

Repeatable annotations

CodingFoundations6 min read
Show how to declare a repeatable annotation @Schedule(cron = "...") so a method can carry it twice, and how to read all of them reflectively.
DebuggingIntermediate5 min read
A library reads annotations with getAnnotation(Tag.class). After a developer adds a second @Tag to a class, the library stops seeing any tag. Explain and fix.

Type annotations

ConceptIntermediate6 min read
What are type annotations introduced in Java 8? Give examples of where they can appear and how tools such as the Checker Framework use them.
LeadershipAdvanced6 min read
Your organisation wants to adopt nullness annotations across many repositories. Options include JSpecify, JSR 305, and framework-specific ones. How do you choose and roll this out?
LeadershipPrincipal7 min read
Java chose to add nullness and other properties as optional annotations checked by tools, rather than in the core type system as Kotlin did. What does that mean for long-term code quality strategy, and what would you standardise across the company?