Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Non-final class at compile-time, final at runtime

Thread view: 
pietdejong@gmail.com - 16 Nov 2006 14:09 GMT
Can somebody tell me under which conditions a non-final class
(compile-time) can become final in runtime?
Thanks
Jan Thomä - 16 Nov 2006 15:58 GMT
Hi,

as far as I know the answer is: under no conditions. You need to declare it
final at compile time.

Best regards,
Jan

> Can somebody tell me under which conditions a non-final class
> (compile-time) can become final in runtime?
> Thanks

Signature

__________________________________________________________
insOMnia - We never sleep...
http://www.insomnia-hq.de

Oliver Wong - 16 Nov 2006 16:36 GMT
> Can somebody tell me under which conditions a non-final class
> (compile-time) can become final in runtime?

   Perhaps you could do some magic with a custom class loader and/or
reflection.

   - Oliver
Thomas Hawtin - 16 Nov 2006 17:20 GMT
>> Can somebody tell me under which conditions a non-final class
>> (compile-time) can become final in runtime?
>
>     Perhaps you could do some magic with a custom class loader and/or
> reflection.

Custom class loader: Well you could load different bytes, but then that
would be a different class.

Reflection: I think setAccessible is the only point of mutation, and
that only affects the reflection object, not the reflectee.

I guess the instrumentation API might work. Or a debugging interface.

Tom Hawtin
Adam Maass - 16 Nov 2006 19:51 GMT
> Can somebody tell me under which conditions a non-final class
> (compile-time) can become final in runtime?
> Thanks

It's a multistep process:

1. Compile all sources;
2. Copy all resulting .class files;
3. Modify the source of the code such that a non-final class is now final;
4. Recompile;
5. Replace the old .class file for the modified class with the new .class
file.

I assume that you're referring to some of the oddities in the spec... this
is the kind of situation that those oddities are intended to address.

-- Adam Maass
Chris Uppal - 17 Nov 2006 12:30 GMT
> Can somebody tell me under which conditions a non-final class
> (compile-time) can become final in runtime?

It would be interesting to hear how you come to be in this situation, and how
you can tell it's happening.   E.g. are you using reflection to discover what
the attributes of the class are, or are you getting runtime errors when you try
to load a sub-class of a supposedly non-final class, or what ?

Or is it, perhaps, something that you are trying to /achieve/ ? (But why ??)

   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.