Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between AccessLevel.PACKAGE and AccessLevel.MODULE?

Tags:

java

lombok

In Lombok, what is the actual difference between

@Getter(AccessLevel.PACKAGE)
private int country;

and

@Getter(AccessLevel.MODULE)
private int country;

?

like image 596
Jade Dezo Avatar asked Nov 16 '17 21:11

Jade Dezo


1 Answers

That is a good question. I tried creating some setters for some test methods and all I got was (decompiled):

for Module AccessLevel:
void setTestModule(Integer testModule) {
    this.testModule = testModule;
}

for Package AccessLevel:
void setTestPackage(Integer testPackage) {
    this.testPackage = testPackage;
}

So, on first look it appears that there is no difference. So, I looked into the source code and all I could verify is that for the time being they are handled the same (from the source here):

lombok.javac.handlers.JavacHandlerUtil.toJavacModifier(AccessLevel accessLevel) or lombok.eclipse.handlers.EclipseHandlerUtil.toEclipseModifier(AccessLevel accessLevel)

/**
 * Turns an {@code AccessLevel} instance into the flag bit used by javac.
 */
public static int toJavacModifier(AccessLevel accessLevel) {
    switch (accessLevel) {
    case MODULE:
    case PACKAGE:
        return 0;
    default:
    case PUBLIC:
        return Flags.PUBLIC;
    case NONE:
    case PRIVATE:
        return Flags.PRIVATE;
    case PROTECTED:
        return Flags.PROTECTED;
    }
}

I think that there will be some future work on that for java 9 probably, but for now it appears to be the same.

like image 188
ialex Avatar answered Nov 06 '22 15:11

ialex