mardi 15 mars 2022

How i can create objects by by reflecting to the dart package

This a java code to automate the process of creating objects using reflection api

 for (File f : files) {
            String fileName = f.getName().split("\\.")[0];
            try {
                Class<? extends Shape> c = Class.forName("shapes.TheShapes." + fileName).asSubclass(Shape.class);
                map.put(i, c);
                i++;
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(ShapeFactory.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

This code in java looping through the file object and takes form it all the classes names in theShapes package ,then it uses class.forname function to create real objects form the classes names. my question is how i can implement like this code in dart.





Aucun commentaire:

Enregistrer un commentaire