aspose file tools*
The moose likes Spring and the fly likes Doubt regarding advising final classes in spring.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Doubt regarding advising final classes in spring.." Watch "Doubt regarding advising final classes in spring.." New topic
Author

Doubt regarding advising final classes in spring..

Sumeet H Singh
Greenhorn

Joined: Jan 03, 2009
Posts: 29
Spring generates proxies for AOP in 2 ways:

If the target object:
-implements an interface - it will use java.lang.reflect.Proxy class to generate a new class
-doesn't implement an interface - it uses CGLIB to generate a subclass and includes the necessary changes depending upon the advise


If this is the case, can spring advise final classes that implement an interface? (as there is no need to subclass our class)


Sumeet
SCJP, SCWCD
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Sumeet K Singh wrote:Spring generates proxies for AOP in 2 ways:

If the target object:
-implements an interface - it will use java.lang.reflect.Proxy class to generate a new class
-doesn't implement an interface - it uses CGLIB to generate a subclass and includes the necessary changes depending upon the advise


If this is the case, can spring advise final classes that implement an interface? (as there is no need to subclass our class)


Yes, it if implements an interface, Spring will create a DynamicProxy of it, the DynamicProxy just holds a reference to the real instance of the class called the target. It does not try to extend it, which you can't do with a final class.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Sumeet H Singh
Greenhorn

Joined: Jan 03, 2009
Posts: 29
Thanks Mark !
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Doubt regarding advising final classes in spring..