Moving new IO to java lang and implicitly import all static methods there for simple source files
david Grajales
david.1993grajales at gmail.com
Sun Jan 19 23:28:58 UTC 2025
Hi Amber Team,
I’ve been thinking about a couple of ideas that might make Java even more
beginner-friendly and for the next iteration of JEP 495
1) Move java.io.IO into java.lang.
This would save developers from having to import java.io explicitly,
especially as projects grow. It’s a small change that could streamline
things right from the start. I suspect the new println() and readln()
methods are going to be heavily used, it would be weird these methods need
an import once the public class is set while System.out.* do not.
2) Implicitly import static methods in java.lang.
Common methods like Double.parseDouble(), Integer.parseInt(), Math.sqrt()
and so on are super handy, but explaining static methods can feel like a
detour for beginners learning algorithms or basic concepts. Implicit
imports could make Java easier to pick up while still allowing the
traditional Class.method() style. This would also make java more similar to
other languages such as Python and JS, helping java to keep competent as a
first language.
For example, a simple script could look like this:
void main() {
var doubleStr = readln("enter a double number");
var doubleNum = parseDouble(doubleStr);
println(sqrt(doubleNum));
}
I get that static imports can sometimes cause ambiguity, but in small,
simple scripts or beginner projects, it’s unlikely people would use
alternative libraries for functionality already in java.lang. This change
could make Java feel more accessible without breaking anything (i guess,
please correct me if i am mistaken)
I hope these not to be hard to implement or to be full of inconveniences, I
understand things are often more complex than what meets the eye.
Best regards and wishes.
I have been playing with primitive pattern matching in switch and I am very
excited about it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20250119/0b446de0/attachment.htm>
More information about the amber-dev
mailing list