Oxnard said:
I'm still trying to beome a bit more comfortable with abstract classes. Here
are the statements:
FontMetrics fm = c.getFontMetrics(c.getFont());
int i = 2 * (fm.getMaxAscent() + fm.getMaxDescent());
This is really as close as you're going to get. If you can guarantee
c.getFontMetrics(c.getFount()) will always return the same instance of
FontMetrics for the same c.getFount() you can try:
int i = 2 * (c.getFontMetrics(c.getFont()).getMaxAcent() +
c.getFontMetrics(c.getFont()).getMaxDescent())));
But I have to agree with the other replies, your code is fine as it is.
Brevity is not an end-in-itself, only combined with clarity.
Note that this has nothing to do with abstract classes. Your question,
and its answers, would remain the same even with concrete classes.
I've myself often wished for temporary variables in Java, though... so I
could do something like this:
int i = 2 * (FontMetrics fm =
c.getFontMetrics(c.getFont()).getMaxAscent() + fm.getMaxDescent());
However, I don't think that's going to be pretty easy to implement in
the compiler. I know a little about compiler theory so I know
something about what compilers can easily do and what they can't.
--
/-- Joona Palaste (
[email protected]) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"You can pick your friends, you can pick your nose, but you can't pick your
relatives."
- MAD Magazine