annotations

What are the similarities and differences between Java Annotations and C# Attributes?

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? W...

@interface default declaration usage in Java

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...

Hibernate Annotations - Which is better, field or property access?

This question is somewhat related to http://stackoverflow.com/questions/305880/hibernate-annotation-placement-question. But I want to know which is better? Access via properties or access via fields? What are the advantages and disadvantages of each? ...

Now that we have annotations in java, is xdoclet legacy?

I came accross the xdoclet project and see it enjoys/ed high popularity. So the question is, now that we have annotations in java: is xdoclet legacy? Or is there something to xdoclet I didn't see/understand. ...

Should I make a constants class for my annotations?

Which is better? @SuppressWarnings("unchecked") @SuppressWarnings(AnnotationConstants.UNCHECKED) Where AnnotationConstants is a typical constants class... public final class AnnotationConstants { private AnnotationConstants() { } public static final String UNCHECKED = "unchecked"; ... } I know that there are a lot of...

EJB3 case-sensitive annotations

We are connecting to a SQL Server to persist our EJB3 objects. These objects are annotated up with @Column. If the column name in the database starts with a capital letter (E.g. OrderName) will the ejb annotation have case sensitivity issues if the element is defined like such: @Column String orderName Thanks ...

Strange SAL annotation warning

Hello, I'm trying to use Micosoft's SAL annotation for my project, however I get the following warning, and I don't know why. As an example, I created a new C++ console application, and have this code: #include <sal.h> class Whatever { public: _Check_return_ int Method(__in int number) ; }; int main() { return 0; } When I ...

How can I find all classes on the classpath that have a specific method annotation?

I want to implement an intialization mechanism that is annotation-based in Java. Specifically, I have an annotation I've defined: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Initialization { /** * If the eager initialization flag is set to <code>true</code> then the * initialized class will be i...

How do I prevent JAXB from binding superclass methods of the @XmlRootElement when marshalling?

I have a class that is annotated as the @XmlRootElement with @XmlAccessorType(XmlAccessType.NONE). The problem that I am having is that the superclass's methods are being bound, when I do not want them to be bound, and cannot update the class. I am hoping there is an annotation that I can put on the root element class to prevent this f...

Saving a XML-Document in a Database (Combination of Hibernate and JAXB) in Java

I am looking for a solution to save a XML-File in a database using Hibernate. The problem is, that the structure of the XML-file is different to the Hibernate-beans. I'm trying to use JAXB to serialize the XML-content to the Hibernate beans. Please imagine the following scenario: There is this xml file: <root> <general> ...

Can Java annotations be unit tested?

I've recently started creating my own annotations and to sport TDD/BDD, I'd want to unit test my annotations to create a clear specification for them. However since annotations are basically merely fancy interfaces which to my knowledge can't be really instantiated directly, is there any way short of reflection to unit test an annotation...

Annotation member which holds other annotations?

Hello! I want to create a custom annotation (using Java) which would accept other annotations as parameter, something like: public @interface ExclusiveOr { Annotation[] value(); } But this causes compiler error "invalid type for annotation member". Object[] also doesn't work. Is there a way to do what I want? ...

The drawbacks of annotation processing in Java?

I am considering starting a project which is used to generate code in Java using annotations (I won't get into specifics, as it's not really relevant). I am wondering about the validity and usefulness of the project, and something that has struck me is the dependence on the Annontation Processor Tool (apt). What I'd like to know, as I ...

How can I inherit Hibernate filters with annotations?

I'm trying to set up a Hibernate filter with annotations. I would like to specify it in a base class and make all sub classes use it but whenever I try to enable it, Hibernate fails to find the filter. Is it possible at all to inherit filter annotations? ...

Force javadoc to ignore an annotation

Hi all, I'm trying to document an annotated interface and include a sample of how it's used in the javadoc. e.g. /** * Here's an example usage: * * <PRE> * @IFaceAnnotation(value="") * public interface IFace { * * @MethodAnnotation("") * public String Method(); * } * </PRE> */ However, Javadoc treats my annotations...

Java Annotations not working

I'm trying to use Java annotations, but can't seem to get my code to recognize that one exists. What am I doing wrong? import java.lang.reflect.*; import java.lang.annotation.*; @interface MyAnnotation{} public class FooTest { @MyAnnotation public void doFoo() { } public static void main(String[] a...

Do you use (or define) non standard annotations, and for what reason. How about recursive annotations?

The question tells it all. For the experts, is there a reason the SUN java 5 compiler accepts recursive annotations (contrary to the langspec), while the later compilers do not? I mean, what could be an argument against recursive annotations. Edit: a recursive annotation is something like: @Panel(layout=BorderLayout.class, nested=...

Why isn't my @BeforeClass method running?

I have the following code: @BeforeClass public static void setUpOnce() throws InterruptedException { fail("LOL"); } And various other methods that are either @Before, @After, @Test or @AfterClass methods. The test doesn't fail on start up as it seems it should. Can someone help me please? I have JUnit 4.5 The me...

Java annotations

I've created simple annotation in Java @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Column { String columnName(); } and class public class Table { @Column(columnName = "id") private int colId; @Column(columnName = "name") private String colName; private int noAnnotationHe...

Is there a way to hide annotations in Netbeans or Eclipse?

Maybe a dumb question, but it would be nice if there was a way to hide or collapse Java annotations when viewing source in Netbeans (or Eclipse). I'm not finding an option and a quick search didn't turn anything up. Is this one of those "you should never want to do that, code folding is a sin!" things? Personally I'd find it useful fo...