C
carl.manaster
Hi,
I'm in the midst of refactoring a "Peak" class, where I noticed a lot
of duplication depending on whether I was in the front half of the back
half of the peak. I got it nicely boiled down into two private nested
classes, Before and After, which extend Half, which implements IHalf.
Each of these, IHalf, Half, Before, and After, is private to the Peak
class. I'll probably be getting rid of the interface before too long,
but I mention it for the sake of telling the full story.
The Peak has
private final Before before
and
private final After after,
which are initialized in the constructor
Now there's a point in the Peak logic where I want to call some methods
of one half or the other, depending. When I do this:
if (heightBefore() > heightAfter())
return meanA(after);
else
return meanA(before);
it works fine, but I thought I would go ahead and inline the meanA
stuff and assign a local variable to be after or before, depending.
Like this:
Half half = heightBefore() > heightAfter() ? after : before;
And it doesn't like this line. It tells me, "incompatible conditional
operand types After and Before". The following two lines compile
without complaint:
Half half = heightBefore() > heightAfter() ? after : after;
Half half = heightBefore() > heightAfter() ? before: before;
(in separate compile events, of course), so I know that the instance
variables are, as I thought, of subtypes of Half.
The only previous message I found in the archives about this topic is a
year old and mentions Eclipse, so I guess it's worth pointing out that
that is my development environment, too. Is this an Eclipse problem, a
Java problem, or a Carl problem?
Thanks for any help.
Peace,
--Carl
I'm in the midst of refactoring a "Peak" class, where I noticed a lot
of duplication depending on whether I was in the front half of the back
half of the peak. I got it nicely boiled down into two private nested
classes, Before and After, which extend Half, which implements IHalf.
Each of these, IHalf, Half, Before, and After, is private to the Peak
class. I'll probably be getting rid of the interface before too long,
but I mention it for the sake of telling the full story.
The Peak has
private final Before before
and
private final After after,
which are initialized in the constructor
Now there's a point in the Peak logic where I want to call some methods
of one half or the other, depending. When I do this:
if (heightBefore() > heightAfter())
return meanA(after);
else
return meanA(before);
it works fine, but I thought I would go ahead and inline the meanA
stuff and assign a local variable to be after or before, depending.
Like this:
Half half = heightBefore() > heightAfter() ? after : before;
And it doesn't like this line. It tells me, "incompatible conditional
operand types After and Before". The following two lines compile
without complaint:
Half half = heightBefore() > heightAfter() ? after : after;
Half half = heightBefore() > heightAfter() ? before: before;
(in separate compile events, of course), so I know that the instance
variables are, as I thought, of subtypes of Half.
The only previous message I found in the archives about this topic is a
year old and mentions Eclipse, so I guess it's worth pointing out that
that is my development environment, too. Is this an Eclipse problem, a
Java problem, or a Carl problem?
Thanks for any help.
Peace,
--Carl