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

  • Home
  • SEARCH
  • 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 7923677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:23:59+00:00 2026-06-03T17:23:59+00:00

I have a situation where I need to programmatically set something that has a

  • 0

I have a situation where I need to programmatically set something that has a parameter of Class<? extends Annotation> but I cannot figure out how to pass in an Annotation class to this method.

For example, if I have javax.persistence.Entity and I try setAnnotation(javax.persistence.Entity.class) I get an error saying Class<Entity> is not applicable for those arguments. However, that is a class that has the @interface attribute; it’s obviously an annotation. What am I doing wrong and how can I appropriately send in a value?

The reason for this is I’m going from Spring XML configuration to class @Configuration. It’s easy enough to do this in an xml file with:

<property name="annotation" value="javax.persistence.Entity" />

but I don’t know what Spring is doing to make that work.

public class Stuff {
    private List<Class<? extends Annotation>> annotations;

    public List<Class<? extends Annotation>> getAnnotations() {
        return annotations;
    }

    public void setAnnotations(List<Class<? extends Annotation>> annotations) {
        this.annotations = annotations;
    }
}

public class StuffTest {


    @Test
    public void test() {

        new Stuff().setAnnotations(Collections.singletonList(javax.persistence.Entity.class));
        // this does not compile
    }
}

Edit:

List list = new ArrayList();
list.add(javax.persistence.Entity.class);
stuff.setAnnotations(list);

works but is there a better way?

  • 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-06-03T17:24:00+00:00Added an answer on June 3, 2026 at 5:24 pm

    This is the API that works for me (both using the Eclipse and javac compilers):

    public void setAnnotations(
      Collection<? extends Class<? extends Annotation>> annotations) {
    

    Of course, this would mean you’d have to change some of the inner workings of Stuff itself…

    Note also the Collection argument type, as Collections.singleton() returns a Set, not a List. Maybe you meant to use a Collections.singletonList() instead?

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

Sidebar

Related Questions

I have situation where I need to make sure that user has completed certain
I have a situation where I need to notify some users when something in
I have a situation where i need to access different rows of result set
I have a situation that need to judge a invalid session and present the
I have situation where I need to change the order of the columns/adding new
I have a situation where I need to initialize/assign variables from the results of
I have a situation where I need to be able to load assemblies in
I have a situation where I need to work with a datagrid and adding
I have a situation where i need to debug a Windows CE application in
I have a situation where I need to update a control referenced in a

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.