Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java default modifier in compilation

Tags:

java

javac

I'm currently working on modifying javac compiler to produce, in a certain way, our own Programming Language.

We want to get rid of Java's default access modifier, making everything that has no access modifier as public.

But so far, I haven't been successfull to find where in Java compilation code this is implemented. I could easily add into one of the declaration phases, but this is a poor solution that we wouldn't like to have.

Any insight on this?

like image 684
Adriano Avatar asked Mar 05 '26 10:03

Adriano


1 Answers

Looking at The class File Format, especially section 4.5 Fields and 4.6 Methods I see the following constants being defined:

ACC_PUBLIC     0x0001
ACC_PRIVATE    0x0002
ACC_PROTECTED  0x0004

However, a specific method (field) of a class may have at most one of its ACC_PRIVATE, ACC_PROTECTED, and ACC_PUBLIC flags set (JLS §8.3.1).

Since there is no ACC_DEFAULT flag and the documentation says at most one (not exactly one) I would guess that having no flags at all means default access.

like image 185
Tomasz Nurkiewicz Avatar answered Mar 06 '26 23:03

Tomasz Nurkiewicz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!