Like in subject - I want to disable using several methods in one (even if it is going to be overriden). Is it possible? How to do that? It will be the best if I will get compile error when I will try to call it. Maybe I should use annotations? Is it possible to do sth like this?

Is this supposed to occur at run time or compile time? At compile time you can control which classes are used during the build. At runtime, if a method is allowed to be overridden then I don't believe you can keep it from being called. You can certainly use flags and such in the super class method to affect how it behaves. From a user interface (GUI) you can use a technique of disabling buttons to limit what the user may do in certain situations.

And for the record, you can't get a compile-time error when you call the method because you need to compile the code before you call it.

I suggest you provide more information on what your real intention/goal is so other alternatives, if they exist, could be provided.

Regards,
Jim

09-05-2013, 06:21 PM

gimbal2

Re: How to disable using one method in another?

Well you could achieve something like that through subclassing and cleverly using modifiers (public, protected, private). But that will require learning the finer points about (abstract) classes, interfaces and inheritance

09-05-2013, 07:45 PM

TrolleY

Re: How to disable using one method in another?

I was curious if some more abstract mechanizm to achieve my goal can be used. I have written some tool called MultiThreadWorker - kind of thread manager which uses specified in constructor amount of threads to execute tasks. It also provides workFinishedListener. I've added by mistake listener which tries to pause work. But method pause waits for all threads for join so there were deadlock. I wanted to prevent to execute public methods from my class by listeners. Or maybe I should just execute listeners in separate thread which will handle all "events"?

09-05-2013, 07:51 PM

KevinWorkman

Re: How to disable using one method in another?

There is already a thread specifically designed to handle events. It's called the EDT, or event dispatching thread. I don't really understand your problem, but it might be worth looking into.