是否可以创建任何只能使用内置类的应用程序?应用程序,如添加或其他基本操作
ex 内置类,如 class String{} class Object{}
I don't understand what you mean fully. If you mean an application that doesn't instantiate any non-standard classes, then yes of course, here:
public class MyApplication {
public static void main(String[] args) {
System.out.println("hello world");
}
}
If you mean an application in which we don't have any non-standard classes at all, then no: you need to have a main()
method in some class somewhere.
Well, yeah. All existing libraries either use built-in methods or use another library that does, or somewhere down the chain built in methods will be used.
All you would be doing is recreating functionality someone already built.
"Any" application no.."an" application yes
You will need to write the class that contains your main(), so strictly speaking, no. But apart from that, you can get quite a lot done with the standard JRE library.
JAVA 是一种面向对象的语言,因此在正常使用中您将定义类。但是,您可以在 JAVA 中进行纯函数式编程,而无需实例化任何用户定义的对象。但是每个函数都必须包含在一个类中,因此您需要至少定义一个包含应用程序逻辑的类。
class MyOnlyClassThatIDontInstantiate{
public static void main(String args[]){
System.out.println("Hello world!");
System.out.println("2 + 3 = "+addNumbers(2,3));
}
public static int addNumbers(int a, int b){
return a+b;
}
}
以上是一个徒劳的应用程序,只使用函数式编程。没有类被实例化,但主要方法必须包含在一个类中。