• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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: 75653
354
  • 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: 24204
44
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: 24204
44
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.



 
Evil is afoot. But this tiny ad is just an ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic