I was trying to make an event system for my Minecraft client. After finishing it I tried to run it and came across an error element value must be a constant expression. This error came from a file EventTarget whose code is:
package me.debug.moon.event;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface EventTarget {
byte value() default EventPriority.THIRD;
}
The line byte value() default EventPriority.THIRD; was the line giving me the error.
If it helps here is the code to my EventPriority file:
package me.debug.moon.event;
public class EventPriority {
public static final Byte FIRST = 0, SECOND = 1, THIRD = 2, FOURTH = 3, FIFTH = 4;
public static final Byte VALUE_AARAY[] = new Byte[] {FIRST, SECOND, THIRD, FOURTH, FIFTH};
}
I looked around in StackOverflow and saw a few questions like this but most of them were due to the libraries they used and were for Android Studio.
Also, I am using Gradle 7.1 (according to the gradle-wrapper.properties file)
I wanted to know if anyone can help me with solving this error
In your EventPriority class you use Byte (uppercase B), which is an object.
You should use byte (lowercase b), which is a primitive.
From the documentation: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.28
A compile-time constant expression is an expression denoting a value of primitive type or a String
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With