• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Spring injection in enum value - question  RSS feed

Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can Spring provide dependency-injection in this example? If so, how?

In the code snippet below, the blank final declaration of the attribute strangeState
is satisfied in the enum's constructor by invoking new Straneness( int q).

If we want to eliminate the new Straneness( int q) by using Spring to assign an instance of Strangeness, we would have a problem.
First, the blank final would flag an error if strangeState is not defined during the constructor execution.
Second, if we simply assign null to strangeState, or remove the final, how can we be sure that Spring's subsequent
replacement of the strangeState value with new Straneness( int q) will not corrupt the bytecode? How would Spring handle this situation properly?

I believe this objective is beyond the capabilities of Spring. Let me know if you agree, or not. Thanks in advance for your constructive insights.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!