If you are creating a Util class in a CDI environment, is it static class?ApplicationScoped?

Asked 1 years ago, Updated 1 years ago, 75 views

When creating a Util class in a CDI environment, which of the following 1-3 would be the best?
I'm thinking about performance and convenience (compatibility with JUnit), but I can't answer which one is better.

1.static class
 2. ApplicationScoped Class
 3. Other than the above

java-ee

2022-09-30 21:38

1 Answers

It depends on what the tUtil class かに refers to, but if you don't have a state (variable instance variable), I think 」1. で would be fine.

For utility classes (such as Apache Commons Lang), implementing common state-independent operations using the static method alone is common (no state).

@ApplicationScoped is used to maintain a state shared by the entire user of the application, such as the value in the drop-down list.

I think that's the standard of selection.In terms of convenience, it is often better to have a utility class that does not require a container or other prerequisite software.The impact on performance does not seem to change significantly depending on the choice between 1 and 3 (depending on implementation).


2022-09-30 21:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.