-
Notifications
You must be signed in to change notification settings - Fork 1
No explicit “public” needed for ctors and methods from unnamed package #34
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
base: java223/main
Are you sure you want to change the base?
No explicit “public” needed for ctors and methods from unnamed package #34
Conversation
Do you refer to JEP495 ? If so: |
How did you get this error message ? |
|
This changeset makes the changes done herein in README.md possible. |
|
OK, so no link with JEP495. Then, unless we are talking about java 24+, it kinda seems against current Java version philosophy. And whatever your answer is, I think it introduces at least one issue: For reference, I had the same kind of issue with field injection. I had to design a recursive method getFieldDeep in BindingInjector, because I also wanted to use getDeclaredField instead of getField in order to get private/protected member. |
|
The purpose and inspiration of this change is to free users from the obligation to write I changed the error “Index 0 out of bounds for length 0”, which appeared only after this change was applied. (Without this change, the error was present, but completely differently spelled). Now for automation/jsr223/n.java package Z;
public class N {
private N() {};
public Object main() {
return null;
}
}the logged error is: Notice above, how “No public constructor in Z.N” appears three times. Whether this should be altered only for the unnamed package or always, is a matter of opinion, and can be changed. I think in most cases nobody will create Having “Simple Source Files and Instance Main Methods (JEP459)”, or “Compact Source Files and Instance Main Methods (JEP 512)” (writing methods without openHAB 5 requires Java 21, I use Java 21, and if there is something Java 24 related, then it is pure coincidence. The most essential thing done here are invocations of
In This change is however not done for finding the runnable function ( and the value of x is changed many times, then Java223ScriptEngine.compile() is executed once, but many times Another simplifications, which can be made for files loaded from Shall I leave here for now |
32cf5d6 to
cbbd11a
Compare
cbbd11a to
de41a12
Compare
|
The current change breaks the "@runscript" and "@rule" annotations for unnamed packages. As the changed implementation does not use |
For .java files in the unnamed package (no
package …;line)publicfor methods and constructors does not need to be specified anymore. Ctors and methods are called, even if they are explicitlyprivate.For .java files with
package …;line still only public constructors and methods (main, eval, scriptLoaded, scriptUnloaded) are considered.The error message
means that no constructor can be accessed outside the package. (package x; and then all ctors are
privateorprotected; in Java223CompiledScriptcompiledClass.getConstructors()returned zero constructors).This could be improved:
to say conditionally if it does not have a
main methodor apublic main method.