Grokking Java Interview Questions
Vote

0% completed

​

Annotations

record Item(String product, @Min(1) int quantity) {} Item item = new Item("apple", 0);

The declaration says that a quantity must be at least 1, and the last line creates an item with a quantity of 0. The program compiles and runs without an error, because nothing in it reads @Min. An annotation only records a statement, and some other code must act on it.

Four questions follow: what annotations are, how long they last, how to write one together with its reader, and how the compiler can read them.

What is an annotation?

Level: Junior

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content