It is necessary that the code displays all objects

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HarrySto
    New Member
    • Nov 2022
    • 10

    #1

    It is necessary that the code displays all objects

    I wrote the code, but it displays only one object when loading, with the rest there is difficulty. Who faced similar situations, how did you solve similar situations?
    And I also want to conduct a full code analysis in order to see all the errors at once, and not when loading the application into work. Are there any services?
    Code:
    public Bean inject(Bean obj) {
            File file = new File("src/main/resources/data.properties");
            Properties properties = new Properties();
            try {
                properties.load(new FileReader(file));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            Field[] fields = obj.getClass().getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                if (field.isAnnotationPresent(AutoInjectable.class) && field.getType() == FirstInterface.class) {
                    try {
                        Object someObject = null;
                        try {
                            Class<?> clazz = Class.forName(properties.getProperty("FirstInterface"));
                            try {
                                someObject = clazz.newInstance();
                            } catch (InstantiationException e) {
                                throw new RuntimeException(e);
                            }
                        } catch (ClassNotFoundException e) {
                            throw new RuntimeException(e);
                        }
                        field.set(obj, someObject);
                    } catch (IllegalAccessException e) {
                        throw new RuntimeException(e);
                    }
                }
                if (field.isAnnotationPresent(AutoInjectable.class) && field.getType() == SecondInterface.class) {
                    try {
                        Object someObject = null;
                        try {
                            Class<?> clazz = Class.forName(properties.getProperty("SecondInterface"));
                            try {
                                someObject = clazz.newInstance();
                            } catch (InstantiationException e) {
                                throw new RuntimeException(e);
                            }
                        } catch (ClassNotFoundException e) {
                            throw new RuntimeException(e);
                        }
                        field.set(obj, someObject);
                    } catch (IllegalAccessException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
            return obj;
        }
Working...