Community
Participate
Working Groups
Let's assume the following definition: @FunctionalInterface public interface IOFunction<T, R> { R apply(T t) throws IOException; } I am writing the following anonymous implementation in some Java file: return new IOFunction<Object, O>() { @Override public O apply(Object t) throws IOException { ... return something .... } @Override public String toString() { return ... some string ... } }; When I save the file it removes the 'public' modifier - which is an error, because the code cannot be compiled without them.
Karsten, can you please have a look?
*** Bug 536556 has been marked as a duplicate of this bug. ***
I have created this class which contains your snippet. The redundant modifier clean up does not remove 'public' anywhere. But it would e.g. remove 'final' when adding 'final' to the 'foo' method. So the clean up action is triggered, but does not cause the failure you are describing. What am I missing? ================================ package test; import java.io.IOException; public final class IOFunctionUsage<O> { public IOFunction foo() { return new IOFunction<Object, O>() { @Override public O apply(Object t) throws IOException { return null; } @Override public String toString() { return ""; } }; } } ================================
Please reopen when the reproduction steps are more precise. Ideally attach a small demo project.
Thanks for taking a look... I logged the duplicate (https://bugs.eclipse.org/bugs/show_bug.cgi?id=536556) bug but now realise that strictly my bug is subtly different... The issue only happens when the anonymous class is created in the interface itself. As you say, it does not surface if you create the anonymous outside of the interface. This is how it works: Create the following interface: public interface X { void B(); void A(); default X y() { return new X() { @Override public void B() { // TODO Auto-generated method stub } @Override public void A() { // TODO Auto-generated method stub } }; } } When you save this code with remove redundant modifiers on it will remove the public from methods A and B in the anonymous implementation of X.
Thanks, this one reproduces the issue. I will investigate this.
New Gerrit change created: https://git.eclipse.org/r/126070
Gerrit change https://git.eclipse.org/r/126070 was merged to [master]. Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=8339650573161d2c730896aa809969d2a9499629
Verified in the build I20180731-2000