10

When I use something like the following in my Quarkus application:

@Path("v1")
@Produces(APPLICATION_JSON)
public class HelloWorldResource {

   @Inject 
   private SomeBean someBean;
}

then I get a warning the following during the build process.

[INFO] [io.quarkus.arc.processor.BeanProcessor] Found unrecommended usage of private members (use package-private instead) in application beans:
    - @Inject field acme.jaxrs.v1.HelloWorldResource#someBean

Everything seems to work just fine so why is Quarkus suggesting that change private to package-private?

geoand
  • 49,266
  • 16
  • 140
  • 156

1 Answers1

16

If a property is package-private, Quarkus can inject it directly without requiring any reflection to come into play.

That is why Quarkus recommends package-private members for injection as it tries to avoid reflection as much as possible (the reason for this being that less reflection means better performance which is something Quarkus strives to achieve).

See section 2 of this guide for more details.

geoand
  • 49,266
  • 16
  • 140
  • 156