在Java中,有以下几种方法来创建对象:
MyClass obj = new MyClass();
MyClass obj = MyClass.class.newInstance();
Constructor<MyClass> constructor = MyClass.class.getConstructor(String.class);
MyClass obj = constructor.newInstance("argument");
MyClass obj = new MyClass();
MyClass cloneObj = obj.clone();
Class<?> clazz = Class.forName("com.example.MyClass");
Constructor<?> constructor = clazz.getConstructor();
Object obj = constructor.newInstance();
MyClass obj = MyClassFactory.create();