【发布时间】:2017-08-02 03:14:00
【问题描述】:
假设我在项目文件夹中有一个名为 DevelopmentFeeCalculator 的文件,现在我想获取这个文件的类名
class main {
public static void main(String [] args) throws Exception
{
String className = System.getProperty(DevelopmentFeeCalculator.class.getName());
String
className1 = System.getProperty("user.dir.DevelopmentFeeCalculator.class.getName()");
String
className2 = System.getProperty("DevelopmentFeeCalculator.class.getName()");
}
}
它们都不起作用。
【问题讨论】:
-
你不需要
System.getProperty,只需要DevelopmentFeeCalculator.class.getName() -
但我的教练告诉我使用 System.getProperty()
-
您到底需要做什么?如果需要类名,则不需要使用系统属性
-
我有一张纸,我的教师画了一张图表,他告诉我们必须使用 System.getProperty 函数。我尝试了很多方法,但没有任何反应。如果我不使用这个功能,我不知道他是否会接受我的项目
-
您可以将系统属性用于许多事情,但您不需要它来查找类的名称。我建议你从头开始:docs.oracle.com/javase/tutorial/essential/environment/…