New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify the use of extension methods #3316
Comments
This is similar to #922 |
I'd guess the opposite: The project would need to be scanned for |
Given these weird problems described in #3261 (and some others I haven't even reported yet, which cause NPE in the compiler), I wouldn't want extension methods to be applied to my entire project all at once. Too much stuff that can go wrong. Extension methods unfortunately are not very stable. I have defined a shortcut in Eclipse called |
Maybe we can use config to limit the scanning scope and improve the efficiency, such as restricting the package in which the extension method resides by project configuration(a global lombok.config). |
I'd propose to go forward with the discussion in #922: as the configuration system allows to have config-files for individual subdirectories (https://projectlombok.org/features/configuration), that would be a great approach to place @ExtensionMethod-Definitions that are valid for many classes. |
I've been on a project recently where the team, although familiar with Lombok and making extensive use of it, nobody knew about I tell that story to explain why I'm not thrilled about using config files for this. A developer who has not encountered tl;dr Java code should be in .java with the rest of the code (including annotations), not hidden away in a config file that most developers aren't even going to know to look for. |
@erizzo: While I can totally relate to getting suspicious looks (I do, too), but that's not an argument against a config-file-possibility! If your team doesn't agree to use such an option in a config file, then simply don't do it. You can already configure lombok to reject the I understand you colleagues perception that And I confess I like to use it to bypass the stream() / collect() dance for simple filter or map situations. Also adding some useful methods to the final String class comes in quite handy ... At first encounter I thought lombok were all about |
@dstango I want to clarify that I'm not arguing against using |
@erizzo Thanks, I got that. But do you think the proposed idea of this issue with So I'd say having such an option in the first place is debatable, and could be decided against on the team level, yet I don't see why we shouldn't have some magic in principle (as config-file or special annotation). BTW: Maybe it's all a variation of this classic paper: https://geo.mff.cuni.cz/~hanyk/NOFY056/prednaska/sphinx-02/_static/Clark-COME-FROM.pdf ;-) |
Why doesn't Lombok define and use extension methods as Manifold does?
Lombok:
Define the extension class of
String
:Use the extension method:
Manifold:
Define extension class of
String
:Use the extension method:
It's really boring and tiring to add
@ExtensionMethod(MyStringExtensions.class)
everywhere I want to use the extension methods, and I think this behavior has gone away from Lombok's purpose of simplifying programming.So if it's possible that Lombok providers an annotation named
@ExtensionClass(String.class)
? A class with@ExtensionClass(String.class)
means that it is an extension class ofString
and it's public-static methods are extension methods ofString
. If I put@ExtensionClass(String.class)
on my extension class, then I can use the extension methods ofString
everywhere in my project, without being forced to use@ExtensionMethod(MyStringExtensions.class)
.What I expect of Lombok:
Define extension class of
String
:Use the extension method(without
@ExtensionMethod
any more):The text was updated successfully, but these errors were encountered: