Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 626849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:27:49+00:00 2026-05-13T19:27:49+00:00

Here is a test class: import java.lang.annotation.Annotation; import java.lang.reflect.Method; public class TestAnnotations { @interface

  • 0

Here is a test class:

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class TestAnnotations {

    @interface Annotate{}

    @Annotate public void myMethod(){}

    public static void main(String[] args) {
        try{
            Method[] methods = TestAnnotations.class.getDeclaredMethods();
            Method m = methods[1];
            assert m.getName().equals("myMethod");

            System.out.println("method inspected ? " + m.getName());
            Annotation a = m.getAnnotation(Annotate.class);
            System.out.println("annotation ? " + a);
            System.out.println("annotations length ? "
                + m.getDeclaredAnnotations().length);
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }
}

Here is my output :

method inspected ? myMethod
annotation : null
annotations length : 0

What I am missing to make annotations visible through reflection ?
Do I need an annotation processor even for just checking their presence ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:27:49+00:00Added an answer on May 13, 2026 at 7:27 pm

    In order to access an annotation at runtime, it needs to have a Retention policy of Runtime.

    @Retention(RetentionPolicy.RUNTIME) @interface Annotate {}
    

    Otherwise, the annotations are dropped and the JVM is not aware of them.
    For more information, see here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 542k
  • Answers 542k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer jmac posted the original question on my behalf. I needed… May 17, 2026 at 3:10 am
  • Editorial Team
    Editorial Team added an answer Overloading opAssign() is like overloading the assignment operator in C++.… May 17, 2026 at 3:10 am
  • Editorial Team
    Editorial Team added an answer Implement a conversion operator on your Complex class: class Complex… May 17, 2026 at 3:10 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

import java.lang.reflect.Array; public class PrimitiveArrayGeneric { static <T> T[] genericArrayNewInstance(Class<T> componentType) { return (T[])
This is my Java 1.5 code (complete example): import org.junit.Test; import static org.junit.Assert.*; import
Here is my code: // Import io so we can use file objects import
I wonder if it possible to not have jython automagicaly transform java objects to
I am new to Java and I am attempting to use JDBC to connect
I have a small test app on Android that is meant to test tracking
I am getting the error cannot issue data. Here is the SSCCE //package mysqltest;
OK so what's the problem with this. I tried using MySQL JConnector for Java
I am trying to open this file in java and i want to know
I would like to use two different implementations for a DAO with Spring's testframework.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.