Are visibility keywords in Java actually methods, for example in Ruby?

As the name suggests, in Ruby, "keywords" like private, public, etc. are actually "methods that work on a class, dynamically changing the visibility of methods" ( http://en.wikibooks.org/wiki/ Ruby_Programming / Syntax / Classes ) is this the same in Java?

Thank!

+3


source to share


3 answers


Not. In Java, this maps to something in the bytecode the JVM understands (and provides). The compiler uses it itself as well.



There is no "dynamic compilation / class manipulation" that happens when the class is loaded, as you can do in Ruby or Perl.

+3


source


No, in Java they are "real" keywords: modifiers go into the generated bytecode. They are not methods.



+1


source


No, it is not. Java is a compiled language, and these keywords are understood by the compiler with specific meanings when it parses your code.

Ruby is not precompiled, so a class definition in Ruby is indeed an executable statement that defines a class at runtime. This is why access modifiers are actually runtime methods in Ruby. Loading classes in Java is completely different.

+1


source







All Articles