Java default modifier in compilation Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Java default modifier in compilation without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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?

Answer

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.

We are here to answer your question about Java default modifier in compilation - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji