Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
I have a Java library I'm considering porting to C#. The Java library makes extensive use of annotations (at both build time and run time.) I've never used C# attributes, but understand that they are the rough equivalent of Java annotations. If I proceed with the port using attributes to replace annotations, what do I need to know? What's going to be the same? Different? What's going to b...
So, I would like to use the findbugs annotations to suppress warnings we deem ok code. Do we need to deploy the annotation.jar and jsr305.jar into our production runtime, or do we only need these jars in the classpath for our Eclipse project and our unix build environment?
I have something like this: public enum En { @Anno1("This is AAA") @Anno2(500) AAA, @Anno1("What is this?") @Anno3(secret="AH239B0EC") BBB, @Anno2(9000) CCC; } And somevhere I have variable (e.g. en1) of Object type, to whitch some En constant assigned. At the same time I know only that en1 of some enum type. The question is: how to get annotations related to...
I have some questions about working of annotations in java. If annotations cannot be converted to bytecode then where does this information go? where does the meta-data goes? How Java Reflection uses this information? How compiler deals with annotations? When we say, @Override public void doSomething(){ } What does a java compiler do with it? I know that it checks the method signature so...
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().e...
What is the practical difference between RetentionPolicy.CLASS and RetentionPolicy.RUNTIME? It looks like both are recorded into the bytecode and both may be accessed at the run-time anyway.
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 "@" addi...
I was trying to go through some online material to learn annotation in java In the following code can any one please let me know what happened to my dear "Hello world" string which i passed in this line: @Test_Target(doTestTarget="Hello World !") @Target(ElementType.METHOD) public @interface Test_Target { public String doTestTarget(); } above is the annotation defined and below is its usa...
 /*
  * Copyright 2003-2004 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Sun designates this
  * particular file as subject to the "Classpath" exception as provided
  * by Sun in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */
package java.lang.annotation;

Annotation retention policy. The constants of this enumerated type describe the various policies for retaining annotations. They are used in conjunction with the Retention meta-annotation type to specify how long annotations are to be retained.

Author(s):
Joshua Bloch
Since:
1.5
public enum RetentionPolicy {
    
Annotations are to be discarded by the compiler.
    SOURCE,

    
Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time. This is the default behavior.
    CLASS,

    
Annotations are to be recorded in the class file by the compiler and retained by the VM at run time, so they may be read reflectively.

    RUNTIME
New to GrepCode? Check out our FAQ X