📄 sweetshop7.java
字号:
// typeinfo/SweetShop7.java
// TIJ4 Chapter Typeinfo, Exercise 7, page 561
/* Modify SweetShop.java so that each type of object creation is controlled
* by a command-line argument. That is, if your command line is "java
* SweetShop Candy," then only the Candy object is created. Notice how you
* can control which Class object are loaded via the command-line argument.
*/
import static net.mindview.util.Print.*;
class Candy {
static { print("Loading Candy"); }
}
class Gum {
static { print("Loading Gum"); }
}
class Cookie {
static { print("Loading Cookie"); }
}
public class SweetShop7 {
public static void main(String[] args) {
if(args.length < 1) {
System.out.println("Usage: sweetName");
System.exit(0);
}
Class c = null;
try {
c = Class.forName(args[0]);
print("Enjoy your " + args[0]);
} catch(ClassNotFoundException e) {
print("Couldn't find " + args[0]);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -