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 6370077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:53:04+00:00 2026-05-25T00:53:04+00:00

Consider this code: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Bar { Foo foo() default FooImpl.FooConstant; }

  • 0

Consider this code:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Bar {
    Foo foo() default FooImpl.FooConstant;
}

Compiler error:

annotation value not of an allowable type

If I replace Foo with FooImpl the code is accepted.

What’s the reason for this behavior?

  • 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-25T00:53:04+00:00Added an answer on May 25, 2026 at 12:53 am

    If I replace Foo with FooImpl the code is accepted.

    I would be very surprised if this compiled, unless FooImpl is an enum.

    Annotation members may only contain the following:

    • primitive type
    • String
    • Class literal
    • annotation
    • enum item
    • or 1-dimensional arrays of any of the above

    It is a compile-time error if the return type of a method declared in
    an annotation type is any type other than one of the following: one of
    the primitive types, String, Class and any invocation of Class, an
    enum type (§8.9), an annotation type, or an array (§10) of one of the
    preceding types. It is also a compile-time error if any method
    declared in an annotation type has a signature that is
    override-equivalent to that of any public or protected method declared
    in class Object or in the interface annotation.Annotation.

    Source: JLS

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

Sidebar

Related Questions

Consider the following code: A.java: import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.RUNTIME) @interface A{} C.java: import
Do you consider this a code smell? foreach((array)$foo as $bar) { $bar->doStuff(); } Should
consider this code block public void ManageInstalledComponentsUpdate() { IUpdateView view = new UpdaterForm(); BackgroundWorker
Consider this code (Java, specifically): public int doSomething() { doA(); try { doB(); }
Consider: print $foo, AAAAAAAA, $foo, BBBBBBBB; Let's say I want to use this code
Consider this code: public <T> List<T> meth(List<?> type) { System.out.println(type); // 1 return new
consider this code : Class Controller_xyz extends Controller { protected $res=' '; public function
Consider this code: template <typename T> class String { public: ... String(T* initStr) {
Consider this code : class App { public static function log($msg) { echo $msg;
Consider this code. public class Class1 { public void ThisShouldNotCompileBecauseOrderWasVoilated() { Call2(); Call1(); }

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.