Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem with compiling abstract class with CW (MAC OS X)



Dmitry Markman <email@hidden> wrote:

>public class AlignCommand extends AbstractCommand {
> public static abstract class Alignment {
> public final static Alignment LEFTS = new Alignment("Lefts") {
> public void moveBy(Figure f, Rectangle anchor) {
> Rectangle rr = f.displayBox();
> f.moveBy(anchor.x-rr.x, 0);
> }
> };
>
> private Alignment(String newDescription) {
> ...
> }
> public abstract void moveBy(Figure f, Rectangle anchor);
> }
>}

I think the way to avoid the problem is to not declare Alignment as
abstract, and to define Alignment.moveBy() as an empty method by default,
with an override in each anonymous subclass. Since all the possible
definitions of Alignment's subclasses are entirely under your control in
exactly one source file, I don't see how you're gaining anything by
declaring it abstract.

I'm wondering if CW may be tripping over the combination of a private
constructor, an abstract superclass, and an anonymous inner class. If you
eliminate the 'abstract' qualifier, and CW still won't compile with the
private constructor, then it could be a bug.

I still think it would be worthwhile to run 'javap' on the output of
'javac', to discover what it's doing about the private constructor. I
suspect it's being promoted to the package-visibility, since the compiler
can't really synthesize an accessor-method that replaces a constructor.
Constructors have the special magic name "<init>", and an arbitrary
synthesized name can't be used as a proxy. In that respect, constructors
are different from any other members that the compiler has to deal with in
synthesizing inner-class accesses.

If javac is promoting the private constructor to package-visibility, then
declaring it private isn't gaining you anything. So just having it be
package-visibility in the source would solve the problem.

-- GG
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.