Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Quarkus warn me about injection in private fields?

Tags:

quarkus

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?

like image 813
geoand Avatar asked Mar 11 '19 11:03

geoand


1 Answers

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.

like image 168
geoand Avatar answered Sep 24 '22 08:09

geoand