I'm also new to Quarkus and have the same curiosity as well. I don't know if the document was updated recently but now there are 2 paragraphs explaining this:
And thanks to our field access rewrite, when your users read person.name they will actually call your getName() accessor, and similarly for field writes and the setter. This allows for proper encapsulation at runtime as all fields calls will be replaced by the corresponding getter/setter calls.
Use public fields. Get rid of dumb getter and setters. Hibernate ORM w/o Panache also doesn’t require you to use getters and setters, but Panache will additionally generate all getters and setters that are missing, and rewrite every access to these fields to use the accessor methods. This way you can still write useful accessors when you need them, which will be used even though your entity users still use field accesses. This implies that from the Hibernate perspective you’re using accessors via getters and setters even while it looks like field accessors.
(You can search for the keyword "rewrite" in that document.)
So I think Quarkus has some kind of engine to rewrite the code at some point (my guess at compile time so that the native image can build the code AOT). And the final result is still using getters and setters like before.
But one thing still bothers me though, does this "rewrite" change all the public
fields to private
? I guess it can't and it won't need to. Because if we write this:
person.name = "Bruce Wayne"
then it would be rewritten to
person.setName("Bruce Wayne")
So public or private, there is no differences anyway, you still use setter and getter at the end.