Announcement Announcement Module
No announcement yet.
Problems instantiating a new ArrayList using new operator. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems instantiating a new ArrayList using new operator.

    Good evening,

    We are building a web application using spring and one of the biggest discussions is that we use dependency injection to instantiate all classes (including JDK classes like ArrayList, HashMap).

    People are wondering if we are not abusing on dependency injection use and they ask us if we should not use it instantiating through the new operator.

    I wonder if instantiating objects using new operator would not cause problems to the application due to lifecycle problems (problems between web container lifecycle and spring microcontainer lifecycle), take the control of the objects out of spring container and memory management issues.

    One of our team mates says that if we use spring we should stick to the end without using the new operator. That we should inject all objects (he was based on a spring article published on Other team mate says that we are abusing on dependency injection use and we should use new operator to instantiate some objects (he was based on an article written by an o'reilly member).

    I would like to know which is the correct approach and if new would cause problems, which are those problems. Can you guys give me a help to find the answers?

    Thanks in advance.

    My best regards.

  • #2
    As you already write it depends and you shouldn't fix your thinking. So the truth is somewhere in the middle :>.