Re: Speed of interfaces vs inheritance
- From: Tom Hawtin <usenet@xxxxxxxxxxxxxxxxx>
- Date: Sat, 30 Dec 2006 20:22:52 +0000
Mike Schilling wrote:
"Chris" <spam_me_not@xxxxxxxxxx> wrote in message news:4596b7a9$0$1612$9a6e19ea@xxxxxxxxxxxxxxxxxxxxxxxIn a particularly time-critical part of my app I need to call a method on an external class in a tight loop. The class can be different in different contexts. I've got two choices: create an interface and have the various different classes implement it, or create an abstract class and have the various different classes extend it.
I seem to recall, in years past, that the interface approach was slower. Is this still the case?
(In this particular situation, either approach works fine, though I personally like the interface approach better).
The only way to answer this question is to write a test.
Yeah, but write a good one...
FWIW, a couple years ago I tested dynamically loading a class through a class loader and having a loop repeatedly calling an (interface) method which threw an exception. Under the Sun server HotSpot, the loop was eliminated. Client performance wasn't too bad either.
I believe interface methods can get slow where the same runtime class is called through a number of different interfaces. A highly unlikely situations, particularly if you were considering an abstract base class.
Tom Hawtin
.
- References:
- Speed of interfaces vs inheritance
- From: Chris
- Re: Speed of interfaces vs inheritance
- From: Mike Schilling
- Speed of interfaces vs inheritance
- Prev by Date: Re: Comparing floating point values in Java
- Next by Date: Re: Advantages and Disadvantages of the Spring Framework
- Previous by thread: Re: Speed of interfaces vs inheritance
- Next by thread: Re: Speed of interfaces vs inheritance
- Index(es):
Relevant Pages
|
|