• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

final class with java reflection

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi......
Is possible to extend (or access ) the Final class using java reflection?
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which Final class?

Do you mean a final class? I have never tried but I am sure it would be possible, but not for us beginners! Moving.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Reflection doesn't have anything to do with creating classes, only probing existing ones. You can break some of Java's programming rules by generating bytecode yourself; this might be one of them. Whether such a class is rejected at runtime will depend on to what extent the verifier is invoked on that class, and whether a security manager is installed.
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to OP:

Nope. If i am not mistaken (I could be and correct me if I am wrong on this), but you can't do this even by using CGLIB or by directly using ASM Object web's famous ClassVisitor ... classes have to be non-final.

Vyas
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anirudh Vyas wrote:
correct me if I am wrong on this



Consider yourself corrected. There's nothing to keep a class file from saying it extends another, final class. Whether or not that class file will be accepted at runtime depends on how closely the JVM is looking at classes, which, in turn, depends on whether the verifier is running, and whether there's a security manager. But as far as defining such a class: of course you can.
 
Anirudh Vyas
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
code ... wheres the code, I can look at JLS or JVM specs too ... It'd be helpful if you can scribble something up.



 
reply
    Bookmark Topic Watch Topic
  • New Topic