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

Discussion in 'Java' started by pietdejong@gmail.com, Nov 16, 2006.

  1. Guest

    Can somebody tell me under which conditions a non-final class
    (compile-time) can become final in runtime?
    Thanks
    , Nov 16, 2006
    #1
    1. Advertising

  2. Hi,

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

    Best regards,
    Jan

    wrote:

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


    --
    __________________________________________________________
    insOMnia - We never sleep...
    http://www.insomnia-hq.de
    Jan =?ISO-8859-1?Q?Thom=E4?=, Nov 16, 2006
    #2
    1. Advertising

  3. Oliver Wong Guest

    <> wrote in message
    news:...
    > 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
    Oliver Wong, Nov 16, 2006
    #3
  4. Oliver Wong wrote:
    > <> wrote in message
    > news:...
    >> 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
    Thomas Hawtin, Nov 16, 2006
    #4
  5. Adam Maass Guest

    <> wrote:
    > 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
    Adam Maass, Nov 16, 2006
    #5
  6. Chris Uppal Guest

    wrote:

    > 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
    Chris Uppal, Nov 17, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nagaraj
    Replies:
    1
    Views:
    856
    Lionel B
    Mar 1, 2007
  2. desktop

    Compile time vs runtime?

    desktop, May 9, 2007, in forum: C++
    Replies:
    16
    Views:
    764
    Ole Nielsby
    May 17, 2007
  3. lielar
    Replies:
    3
    Views:
    1,261
  4. puzzlecracker
    Replies:
    2
    Views:
    471
    Daniel Pitts
    Jul 25, 2008
  5. Carter
    Replies:
    2
    Views:
    504
    Carter
    Mar 4, 2009
Loading...

Share This Page