Does anyone create custom annotations in their game code?

I know basically what annotations are and use ones like @Override. I was curious, do people here create custom annotations for their game code and if so why? I feel like I may be missing something here.

I’m not exactly sure of what you call an “Annotation”. An annotation to me is something like this

// Annotation

If this is correct, all you have to do is //(Your text here) to have annotations. If this is wrong, sorry for any inconvenience.


I think what you are referring to are comments. I am thinking more about Java Annotations which allow you to attach metadata to your code.

Ah, your right, I’ve just seen comments referred to “annotations” so much I got them confused. In that case what you’ll need to do is this


However, you’ll need some code to go along with the annotation, as below.

public @interface Hi {


I understand the basic mechanics of how annotations are created. I was more interested in the purposes people use custom annotations. Are there issues in game programming that people here use annotations to help solve.

The most amazing thing about Annotations is preprocessing java code.

Actually that’s also what [icode]@Override[/icode] does. It helps the Eclipse/IntelliJ/WhateverIDE’s processing of the code. In this case it warns you if you mistyped the method you intended to overwrite, but actually doesn’t exist under that name.

So what I’ve seen is that they are sometimes used for bytecode manipulation or reflection. See things like MappedObjects or (also Riven’s) LibStruct.

Sadly I can’t find another example not involving Riven at the moment :persecutioncomplex:

To say it abstract: They are used for providing AST information that can’t be given in the default Java AST without annotations.

And let’s not forget project lombok for some clever hacks involving annotations and the JVM.

I definitely use [icode]@Override[/icode] as that helps alot, especially if you’re using an interface and modifying code. [icode]@SuppressWarnings[/icode] is also useful, especially when I want to get rid of those lightbulbs because I’m OCD like that :stuck_out_tongue:
I had created my own annotation once ([icode]@echo[/icode]) that would alert me anytime a method was not handling error-cases, but that really was only for debug anyway.

I want to use them just as a learning experience. I sortof feel that my learning of Java stopped at Generics, so I want to add some new things. I have an idea that annotations could cut down on boilerplate code…

We use custom annotations all the time at my work. I dont author them but I do support the devs using them in our API.

:frowning: don’t forget my awesome resource injection lib (topic).
I used annotations to collect all used resources at compile time and be able to optimize them (declare single images in code, but the compiler will add them together into texture atlases)

I knew there was something! I mean… seriously… I did…

I guess nobody’s using JDK 8 yet, huh.