-
Notifications
You must be signed in to change notification settings - Fork 125
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
Extension methods with @Self doesn't work sometimes. #490
Comments
Hi @pangwa. Can you provide the compile error message or stack trace? Also the class where it fails? That would help me diagnose this issue. Thanks :) |
below is the error message: It happens in several places , such as spring controller/services(annotated with @RestController or @service). |
Hey Scott, I created an example project to demo this issue. @Extension
public class ObjectExt {
public static Optional<@Self Object> asOpt(@This Object it) {
return Optional.ofNullable(it);
}
} then Optional<String> optionalString = "Hello, World!".asOpt(); This extension works in our production project using jdk 17, but stops to compile in jdk 21. In the example project, it does not work even in jdk 17. So it does seem flaky even in the same jdk version.
|
Describe the bug
I wrote an extension class which returns the
ApiResult<T>
whichT
was supposed to be the type of the caller. I wrote the extension method exactly as below.It works in most cases, but in some files, the code can't be compiled.
The same code could be compiled in some files, but in a little files, it can't, I don't know why.
To Reproduce
Implement an object extension as above.
Expected behavior
Code could be compiled.
Screenshots
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: