Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

237
Vistas
Can an annotation type without a @Target be used anywhere?

The Java Tutorials says what follows:

If an @Target meta-annotation is not present on an annotation type T , then an annotation of type T may be written as a modifier for any declaration except a type parameter declaration.

https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/annotation/Target.html

Other manuals says that if @Target is not present an annotation can be used in any place except TYPE_USE or TYPE_PARAMETER scenarios.

I'm not really sure about what "parameter declaration" means in that case. This class compiles, and the annotation "@EveryWhere" is present really everywhere, without any @Target annotation. Including cast operations, lambda parameters and generics declarations.

import java.util.ArrayList;
import java.util.function.Predicate;
@interface EveryWhere{}
public @EveryWhere class  AnnotedEveryWhere<@EveryWhere T> extends @EveryWhere Object{
    @EveryWhere int i = 0;
    @EveryWhere <@EveryWhere T> String method(@EveryWhere ArrayList<@EveryWhere String> array) {
        @EveryWhere Predicate<@EveryWhere ArrayList<@EveryWhere String>> pred = 
                (@EveryWhere ArrayList<@EveryWhere String> lambdaParameter)->{
                    @EveryWhere ArrayList<@EveryWhere String> insideLambda = new @EveryWhere ArrayList<@EveryWhere String>(); 
                    return (@EveryWhere boolean) true;};
        return (@EveryWhere String) "String";
    }

}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

It depends on Java version. Java SE 18 says

If an @Target meta-annotation is not present on an annotation interface T, then an annotation of type T may be written as a modifier for any declaration.

Unfortunately https://javaalmanac.io does not do diffs at the level of detail necessary to find out in which version it changed.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda