Reputation: 181
So i have this code for isCancelled in SwingWorker
boolean isCancelled() return true;
and its giving me the error
attempting to assign weaker access privileges; was public error
I dont know how to fix it. Can anyone help me? Thank you
Upvotes: 2
Views: 8299
Reputation: 2336
Because if override methods you use same access in superclass or extend(package -> protected -> public).
Example if superclass:
boolean isCancelled(){}; // package local default access
protected boolean isCancelled(){};
public boolean isCancelled(){};
In your sub class use(relatively):
@Override
boolean isCancelled(){}; //or add protected or public
@Override
protected boolean isCancelled(){};//or change public
@Override
public boolean isCancelled(){};
Upvotes: 2
Reputation: 4646
You can try this like the previous poster said:
@Override
public boolean isCancelled(){
return true;
}
But you may also want to consider whether you really need a method at all, when you may only need to have a variable:
public boolean isCancelled = true;
Upvotes: 1
Reputation: 1502806
Firstly, you need braces around your method body.
Secondly, the way you're currently declaring it uses package access, but the isCancelled
method is public, so you'd have to override it with another public method.
Thirdly, the method is final
anyway, so you can't override it in the first place. It's not clear what you're trying to achieve, but this isn't the way to go.
Upvotes: 3