Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid warning about redundant specification of type arguments with anonymous inner classes #1358

Closed
mauromol opened this issue Apr 22, 2022 · 5 comments

Comments

@mauromol
Copy link

Ensure the following option is set to warning or above:
Right click on project => Properties | Java Compiler | Errors/Warnings | Enable project specific settings | Redundant type arguments (1.7 or higher), under Generic types.

Consider this:

package testdiamond

class TestDiamond {
	ArrayList<String> list = new ArrayList<String>() {
		
	}
}

Greclipse compiler shows a warning on new ArrayList<String> saying:

Redundant specification of type arguments <String>

However, if you change that line to:

ArrayList<String> list = new ArrayList<>() {

this of course produces an error, because:

Cannot use diamond <> with anonymous inner classes
@eric-milles
Copy link
Member

Can you retest with latest? I think I have it setup right but no longer get the warning:
image

@mauromol
Copy link
Author

Hmmm... it's strange. I don't get this error for the above simple case any more, but (at least in 4.8.0.v202210271251-e2206) I still get it on another project of mine... Trying to understand what's different...

@mauromol
Copy link
Author

I was not able to reproduce with a simple test case. But there's a class in which I still have this problem, see here:

immagine

The original problem I see is the second red row on the right, but, as you can see, even the simple ArrayList extension produces the error. I don't know why this happens here but not on the simple test-case project. The option setting related to the redundant type argument warning is the same. Tried to add @CompileStatic to the simple test case but didn't help to reproduce... Any idea?

@mauromol
Copy link
Author

mauromol commented Nov 14, 2022

Ok, I found the way to reproduce. The problem DOES NOT show up if the project uses a JavaSE-1.8 execution environment, but DOES show up if it uses a JavaSE-11 execution environment.
So, try to switch your project to Java 11 and see. I get it now even with the simple class above.

I also tried with the very latest Greclipse (4.8.0.v202211132335-e2206).

@mauromol
Copy link
Author

Seems to be fixed in 4.8.0.v202211201901-e2206, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants