val causes intellij to show an invalid error when used alongside an anonymous class
See original GitHub issueval is supposed to infer the type of a value and make it final, so you should be able to use them in anonymous classes. In fact you can do this! Intellij doesn’t believe you though:
public class ValTest {
public void doSomething() {
val foo = new Foo();
val bar = new Bar();
foo.setBazListener(new BazListener () {
@Override
public Bar onBaz() {
return bar;
}
});
}
}
When using this code there is an error on bar
in return bar
that says “Variable bar is accessed from within inner class, needs to be declared final”. I agree, however val indeed does make it final. This code actually compiles and runs fine. I’m currently using android studio 1.2.1.1, and I think it’s based off of idea 14.
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
accessing private member in object class/anonymous object is ...
I was trying to create an object class (to emulate a static class in java) using the latest version of the Kotlin compiler...
Read more >Java error highlighting showing errors that are incorrect
We have a large Java project using gradle and the error highlighting keeps getting in a bad state on Mac. If I clear...
Read more >Names for anonymous classes in interfaces are malformed
Names for anonymous classes in interfaces do not start with enclosing class name ( .DefaultImpls is missing). example: import java.util.
Read more >IntelliJ IDEA 2018.3 (183.4284.131) Release Notes - YouTrack
Feature IDEA‑198897 Parameter hints: Smart argument completion should insert comma if...
Feature IDEA‑127245 Open all files from favorites list
Feature IDEA‑196706 Multithread model for new...
Read more >IntelliJ highlights errors that don't exist
try to recreate project jdk, then invalidate caches. Also make sure you didn't configure classpath with different version of the same class.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The update should be available in the next version of plugin (0.12) and will work only for new versions of IntelliJ Idea (2016.2)(build >=146.1154)
I just filed a issue IDEA-153706 for Intellij.