🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #3023

Re: Why are methods final?

#3023
From: John Collins
Date: Mon, 25 May 1998 00:00
51 lines
2865 bytes
Declaring methods final allows the compiler, if it wishes, to inline the
code... basically making it a typed-checked macro instead of a subroutine
call.  It runs faster and in the case of really short subroutines actually
takes less code.  Of course the compiler is not _required_ to do so.

Also, declaring a method as final prevents a user of the class from
overriding functionality you feel would make the class unsound if altered.
Not sure if that was a concern with Vector or not.


Since you are using JBuilder I would think that as an alternative to
overriding these methods you could, if you were interested in tracing, just
enable tracing for "java" (package) classes and then put a breakpoint on the
"insert" and "delete" methods.  Then change the properties of the
breakpoints to logging and not stopping.

Now throwing a Runtime (unchecked) exception is possible but probably not
beneficial.  Throwing a checked exception is probably not possible since
that would change the signature of the function (interface, not merely
implementation).

I question why you would want to throw an exception when an element is
inserted and deleted.  Exceptions are not really events.  They are aborts
and the caller would have to try/catch the exception every place the insert
or delete operators were used in your code or standard or 3rd party code
that used a Vector.  Perhaps I just don't grasp something obvious about what
you are trying to do.

If you just want to check some of your own code you could create a proxy or
facade class that would contain a private standard java.util.Vector class,
which would provide as much of the Vector classes interface as you needed
and forward all calls to the internal java.util.Vector class.  You could
call your own code in this case, before and after the insert was actually
carried out.

If you want to spy on what code that you didn't write is doing then I
suggest going the debugger route instead.

bill wrote in message <3549CE7D.1BA40EB4@xsite.net>...
>Hi Foks,
>
>I wanted to subclass java.util.Vector so that my vector would throw
>events when an element was inserted or deleted. Not easily done. The
>insert and remove methods in Vector are final and cant be overridden.
>I'll find a workaround, but why are the above methods defined as final ?
>
>Thanks,
>
>Bill.
>
Technical Details
Message-ID: <6kc2q6$62k5@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3549CE7D.1BA40EB4@xsite.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,bf5509b9ebccfe15
X-Google-Attributes: gid1089d0,public
From: "John Collins" <jcollins@access.digex.net>
Subject: Re: Why are methods final?
Date: 1998/05/25
Message-ID: <6kc2q6$62k5@forums.borland.com>
X-Deja-AN: 356357262
References: <3549CE7D.1BA40EB4@xsite.net>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.api