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

P

pietdejong

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

Jan =?ISO-8859-1?Q?Thom=E4?=

Hi,

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

Best regards,
Jan
 
O

Oliver Wong

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
 
T

Thomas Hawtin

Oliver said:
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
 
A

Adam Maass

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
 
C

Chris Uppal

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top