标题: Java 21 新特性:Unnamed Classes and Instance Main Methods [打印本页] 作者: 立山 时间: 2023-10-11 18:31 标题: Java 21 新特性:Unnamed Classes and Instance Main Methods Java 21引入了两个语言核心功能:
未命名的Java类你说
新的启动协议:该协议允许更简单地运行Java类,并且无需太多样板
下面一起来看个例子。通常,我们初学Java的时候,都会写类似下面这样的 Hello World 程序:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
复制代码
对于程序的功能来说,这里有太多的混乱的代码、太多的概念、太多的构造。
The static modifier is part of Java's class-and-object model. For the novice, static is not just mysterious but harmful: To add more methods or fields that main can call and use the student must either declare them all as static — thereby propagating an idiom which is neither common nor a good habit — or else confront the difference between static and instance members and learn how to instantiate an object.