Forums Register Login

Regarding annotations

+Pie Number of slices to send: Send

Hi All,

I am new to annotations. Please clarify the followings on annotations

1. When should we go for annotations?

2. What is the advantage of annotations? How annotations helps the developers?

3. Whether the annotations affects the behavior of the class @ run-time? if yes, please explain.

4. How the custom annotations are processed by apt?




+Pie Number of slices to send: Send
Read Annotations for start.
+Pie Number of slices to send: Send
Hi Kemal,

I have already gone through the link.
The link doesn't answer my questions.
+Pie Number of slices to send: Send
Ok, then which kind of annotations are you having trouble with? Compile time annotations? Run time annotations? Documentation annotations?
+Pie Number of slices to send: Send
I want to understand the annotations in general.
+Pie Number of slices to send: Send
The posted link has a good general explanation of annotation. Which part are you having trouble with?
+Pie Number of slices to send: Send

If you think the above link has answer for my questions, Could you please give the answer for each questions.
+Pie Number of slices to send: Send
1) When you want to provide your code with some additional information (metadata).

2) Annotations per se are not very useful. However, they can be very helpful when combined with tools that can use the information they provide. E.g. you can annotate some methods of your class to be used only for testing purposes (hence, JUnit can use that information).

3) No, they don't affect the way your code compiles/executes (meaning functionality of your class or method cannot be changed just because you add annotation).

4) Annotation Processing Tool
1
+Pie Number of slices to send: Send
 

Thennam Pandian wrote:If you think the above link has answer for my questions, Could you please give the answer for each questions.


If it does have the answer to your questions, why should we simply repeat its contents here? If it doesn't - or you can't follow the explanation - then you need to be clear about what it is you don't understand. Nobody is going to provide an "annotations tutorial" in a couple of paragraphs.

Winston
+Pie Number of slices to send: Send
If everybody can understand everything from the reference link or tutorial , then what is the need of this forum?
+Pie Number of slices to send: Send
 

Thennam Pandian wrote:If everybody can understand everything from the reference link or tutorial , then what is the need of this forum?


To answer specific questions. It's not supposed to be a substitute for research.

Winston
+Pie Number of slices to send: Send
Annotations are designed to reduce the complexity of xml-based configuration.

WP
+Pie Number of slices to send: Send
Annotations in my opinion should only be used for tools to inspect and perform actions on source code. They should not be used to make code itself run differently.

I really hate frameworks that use annotations to make the code run. As an example, in my opinion JAX-RS is a huge offender.
+Pie Number of slices to send: Send
Stephen, Would you rather map your database entities using xml (now two files to change) or @Entity within the pojo itself?

WP
+Pie Number of slices to send: Send
I think annotations are very good to do that sort of thing. After all, you're telling a tool something about your code, so it can work with your code more easily.

One of the things I was referring to, is how in JAX-RS you tell the framework which method it has to run when a specific event occurs using an annotation above that method signature. That's just *wrong*. We have interfaces for that.
+Pie Number of slices to send: Send
 

Stephan van Hulst wrote:Annotations in my opinion should only be used for tools to inspect and perform actions on source code. They should not be used to make code itself run differently.

I really hate frameworks that use annotations to make the code run. As an example, in my opinion JAX-RS is a huge offender.



How about Transactional annotations, DI annotations?

Sure, runtime annotations introduce a new paradigm in Java, but I don't think it is a bad thing. It requires developers to shift their thinking, and introduce a learning curve, but that's not the worst thing in the world.
+Pie Number of slices to send: Send
 

Thennam Pandian wrote:If everybody can understand everything from the reference link or tutorial , then what is the need of this forum?



If reading that reference link doesn't help you understand, it's highly unlikely that reading a post on this forum can make you understand. The reference is written by professional technical writers who spend considerable time thinking about how to present information clearly, and (over time) has been vetted by thousands of programmers.

Sure, it's understandable to have difficulty with certain aspects, and you are welcome to ask specific questions. However, before you do RTFM!
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 994 times.
Similar Threads
Adding Annotations dynamically at Runtime
Strange error after em.persist
How to Develop Web Service with Annotations
How the Annotations are Processed?
need to know how to create annotation
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 06:52:23.