What I have is this:

public abstract class Ability {
    public class Action extends Ability{}
    public class Reaction extends Ability{}
    public class Support extends Ability{}
}

I have it like that so I don't have all of the Ability-extended classes in their own .java file (to save room and to keep tidy while coding). And so i can access each class by only importing blah.blah.Ability, then making a new Action Ability like so:

Ability.Action Jump = new Ability.Action();

My question is, does doing it this way lead to any adverse side effects? such as memory leaks, or something of similar unwanted nature.

Recommended Answers

All 5 Replies

If your inner classes are implemented in a way that does not cause a compiler error, I do not think you can get errors such as memory leaks or anything of that nature. However, when defining inner classes inside an abstract class, I'd be careful about what techniques and syntax are/aren't allowed.

What an interesting idea! I haven't tried this, but some questions need answering:
Ability is abstract, so you can't instantiate it. The inner classes are not static, so they need an instance of Ability. ?
Since each of the inner classes extend Ability, they each inherit the inner classes, so presumably you could do al kinds of unintended recursive things?

Ability is abstract, so you can't instantiate it. The inner classes are not static, so they need an instance of Ability. ?

what's the difference between static inner classes and regular inner classes?

Since each of the inner classes extend Ability, they each inherit the inner classes, so presumably you could do al kinds of unintended recursive things?

THAT is exactly what I thought when I woke up 5 minutes ago, lol. As long as I don't do something silly like,
Ability.Support spt = new Ability.Reaction.Support();, I think it should be fine.

Also, can you even access an extended class's inner classes?
hmm...

After reading that article, and doing some testing, i decided that it would be easier and more convenient to make each inner class it's own class. Thanks for all the help and comments!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.