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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:28:52+00:00 2026-05-11T07:28:52+00:00

I have just discovered this feature. Declaring an interface using the @interface syntax allows

  • 0

I have just discovered this feature.

Declaring an interface using the ‘@interface’ syntax allows you to put a default value.

public @interface HelloWorld {       public String sayHello() default 'hello world'; } 

This is something new for me. How is that default value suppose to be used.

I cannot find references to that, because the www is full of java interface documents prior to ‘@’ addition in Java 1.5 ( was it on .5 or in .4? )


EDIT

Thanks for the answers ( I was somehow close to ‘annotation’, for I use the tag already ) 😛

I knew I should’ve read that document years ago!!!… let’s see…

Many APIs require a fair amount of boilerplate code. For….

  • 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. 2026-05-11T07:28:53+00:00Added an answer on May 11, 2026 at 7:28 am

    You have just written an annotation.

    Regarding the default statement in particular: This is used because annotations and interfaces can’t have constructors, so this is the only way to have a default value for an annotation attribute. From the Java Language Specification:

    An annotation type element may have a default value specified for it. This is done by following its (empty) parameter list with the keyword default and the default value of the element.

    Defaults are applied dynamically at the time annotations are read; default values are not compiled into annotations. Thus, changing a default value affects annotations even in classes that were compiled before the change was made (presuming these annotations lack an explicit value for the defaulted element).

    I note that none of the annotations in java.lang.annotation use default values, though.


    Usage: You have an annotation @HelloWorld with an attribute sayHello. You could put it on a class like this:

    @HelloWorld(sayHello="Hi") public class MyClass { } 

    Since you have a default value, you could just put

    @HelloWorld public class MyClass { } 

    (Note that the document says, "In annotations with a single element, the element should be named value"; I believe the only reason to do this is that you could just write @HelloWorld("Hi") without having to name the parameter.)

    As written, your annotation can be used on any valid program element (including methods and variable declarations). You can change this with the @Target annotation.

    Finally, setting the RetentionPolicy lets you decide if the annotation should be discarded by the compiler, discarded by the VM, or kept always.


    Two packages that might also be interesting: javax.annotation and javax.annotation.processing. And here is an example of using annotation processing for source code analysis.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I think your benchmark is flawed. Console.Write is an I/O… May 11, 2026 at 12:53 pm
  • added an answer You can try this approach for testing: protected void Application_Error(object… May 11, 2026 at 12:53 pm
  • added an answer I would use a hybrid of 1 and 2. Use… May 11, 2026 at 12:53 pm

Related Questions

I have just discovered the nifty unhandled exception handler for cocoa-touch. Now that I
I have just discovered that if generating assemblies via Reflection.Emit, the .NET framework keeps
I have just inherited a server application, however it seems that the only copy
I have just installed C# for the first time, and at first glance it
I have just set up cruise control.net on our build server, and I am
I have a fairly infrequent problem occuring with source control. In the example here
I love working with Rails but I keep tripping up against my own inefficiency:
I'm a Java programmer, but not a JavaScript programmer. I have just discovered YUI,

Trending Tags

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

Top Members

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.