J.III · Java 25 practice question

A software engineer writes a helper method inside a class that is not itself generic. Under JLS SE 25, what distinguishes this method as a generic method?

Choose one answer
Check answer and explanation

Correct answer: It introduces at least one type variable in its own declaration

Explanation

Declaring one or more type variables on the method itself makes it a generic method, even if the enclosing class is non-generic.

Common trap

Returning a wildcard-parameterized type uses an existing type rather than declaring method-level type variables. Overriding a generic method does not by itself declare new type variables on the overriding method. Overriding a generic method does not by itself declare new type variables on the overriding method.

Source: JLS SE 25 §8.4.4. Generic Methods
Checked against the cited text on 2026-11-25.

Report an error in this question