• Post Reply Bookmark Topic Watch Topic
  • New Topic

spring bean with inner classes  RSS feed

 
sam bartl
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a spring bean with fields which are injected by spring these fields are other springbeans.
If I have a static inner class in this bean I cannot use any of the injected fields, If I make a non static inner class I can but the inner class will point to this the containg class .
I will be instatiating these inner classes in methods so I am assuming all the instances will be garbage collected when method completion finishes am I right ?
 
sam bartl
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sam bartl wrote:I have a spring bean with fields which are injected by spring these fields are other springbeans.
If I have a static inner class in this bean I cannot use any of the injected fields, If I make a non static inner class I can but the inner class will point to this the containg class .
I will be instatiating these inner classes in methods so I am assuming all the instances will be garbage collected when method completion finishes am I right ?


what I mean in code is



I can write the corhandler outside the method making it static but I wont be able to use workflowservice as it is not static
 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the nested class has relevance outside its enclosing class, then make it a top-level class. If it has no relevance outside the enclosing class, then there's no reason to make it static.
 
sam bartl
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does not have relevence outside this class , making it static is of course is better than non static as non static have reference to the containing class and moreover garbage collecter will it clean up once inner class instance lifecycle is over inside the method ?

 
Jayesh A Lalwani
Rancher
Posts: 2762
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instance of any class will be garbage collected when there are no references to that instance.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!