DEV Community

Discussion on: Explain Java annotations and how to use them like I'm 5.

Collapse
 
nestedsoftware profile image
Nested Software • Edited

Here is an example of a compile time custom annotation that automatically generates custom builders for classes that you annotate:

baeldung.com/java-annotation-proce...

Here is an example of a run time custom annotation that is used to convert objects to json:

baeldung.com/java-custom-annotation

I'd say in practice it's fairly rare for application developers to write custom annotations. It's more common to use annotations that are either part of Java itself, or part of some 3rd-party library or framework.

They look a lot like Java annotations, but I think Python decorators are quite a bit simpler than the Java annotations - you are just wrapping some additional code around a class, method, or function at run time. When you call a method wrapped by a decorator, the decorator will be applied directly, whereas I don't believe that is the case for annotations in Java. However, I guess decorators can be used in kind of a similar way to run time annotations in Java. Decorators in python:

realpython.com/primer-on-python-de...

Thread Thread
 
baenencalin profile image
Calin Baenen

Thanks for the resources, helps a lot in my understanding in the language!