In case of multiple constructor candidates give preference to the public one
See original GitHub issueSpeaking of immutable dto classes
, there are many cases where there are several non-default constructors in it. Current implementation of PreferredConstructorDiscoverer.Discoverers.DEFAULT can’t resolve these cases without @PersistenceConstructor
.
Usually this is not a big problem, however when using libraries such as Lombok or Immutables this adds additional inconvenience. These libraries can generate additional private constructors for builders contructor(builder)
or copy methods copyOf(self)
/with*
The idea is not to return null when several non-default constructors are found, but try to find one public among them (if it is the only public one) and return it.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Why can I create another bean if a @Primary bean exists?
@Primary just tells Spring which bean to give precedence to if there are two or more possible candidates. You can always be explicit....
Read more >Choosing from multiple beans in the context - Manning
In this case, Spring selects the primary bean for injection. You can explicitly select a specific bean using the @Qualifier annotation. If none ......
Read more >Spring @Qualifier Annotation | Baeldung
This annotation defines a preference when multiple beans of the same type are present. The bean associated with the @Primary annotation will be ......
Read more >Are Multiple Constructors possible in Java? - Tutorialspoint
There can be multiple constructors in a class. However, the parameter list of the constructors should not be same.
Read more >Removing repetitive code (overloading methods and ...
Creating multiple methods with the same name in a class. ... is in fact a special case of the second constructor - the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, this can solve the problem. In immutables also that should be available with:
Аlthough this is solved with two additional lines of code, it becomes very annoying when you need to turn this in almost every dto. One of the cool features of immutables is that you can make custom annotations with style settings and reuse them, but you can’t put a constructor that is declared explicitly (and not in the style annotation) there. Here are my considerations.
Thanks for bringing up this topic. Let me take it to the team so we can discuss your proposal.