How would I do the Dart equivalent of this Java code?
Class<?> c = Class.forName("mypackage.MyClass");
Constructor<?> cons = c.getConstructor(String.class);
Object object = cons.newInstance("MyAttributeValue");
(From Jeff Gardner)
Syntax: var object_name = new class_name([ arguments ]); In the above syntax: new is the keyword use to declare the instance of the class.
String type = MyClass(). runtimeType. toString();
In Dart, we work with objects. Even numbers or string literals are objects.
Instance Method in Dart:Unless the method is declared as static it is classified as an instance method in a class. They are allowed to access instance variables. To call the method of this class you have to first create an object.
The Dart code:
ClassMirror c = reflectClass(MyClass);
InstanceMirror im = c.newInstance(const Symbol(''), ['MyAttributeValue']);
var o = im.reflectee;
Learn more from this doc: http://www.dartlang.org/articles/reflection-with-mirrors/
(From Gilad Bracha)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With