liveBook · Manning

Attribute

As explained in 100 Java Mistakes and How to Avoid Them

An annotation is structured metadata attached to program elements that tools or language processors can inspect.

An annotation is structured metadata attached to a program element. Language processors and tools can inspect it to recognize intended behavior, configure processing, or report mistakes. section 1.3.2 section 10.7

A missing test annotation disables the test

public void parsesInput() { // assertions } Without @Test, a test framework may never execute this method. The dangerous result is a test suite that appears complete while silently omitting coverage. The same failure can arise from importing an annotation from the wrong framework, such as JUnit instead of TestNG. section 10.7

Avoid annotation-related failures by checking:

  • Whether the required annotation is present and imported from the intended framework. section 10.7
  • Whether the annotated declaration satisfies the framework’s visibility, static, return-type, nesting, naming, and parameter requirements. section 10.7
  • Whether a static analyzer understands the annotation; custom annotations may be needed to describe application methods, and analyzers may require configuration or extensions. section 1.3.2
Figure 10.2 Malformed test methods have no Run gutter icon.
figure

Use the missing Run gutter icon as a practical signal that a test method may be malformed or undiscovered. section 10.7

How 100 Java Mistakes and How to Avoid Them covers it

How deep it goes
Explains annotation-driven discovery through malformed test cases and analyzer limitations, but does not detail annotation declaration or processor internals.
Examples
Uses missing or wrongly imported @Test annotations, malformed test declarations, and IDE warnings as concrete examples.
What it assumes
Assumes Java and unit-testing familiarity while teaching how annotation presence, imports, and declaration shape affect test execution.
What you can do after
Diagnose undiscovered tests and configure or extend static analysis without blindly applying suggested fixes.
How it connects
Connects annotations with static analysis, unit testing, test discovery, and framework configuration.

Also explained in

Compare how 26 books explain attribute →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 Java Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.