Open Eskibear opened 4 years ago
The code does not compile, not an issue.
It compiles.
$> java -version
openjdk version "14.0.1" 2020-04-14
OpenJDK Runtime Environment Zulu14.28+21-CA (build 14.0.1+8)
OpenJDK 64-Bit Server VM Zulu14.28+21-CA (build 14.0.1+8, mixed mode, sharing)
$> tree
.
├── Foo$Bar.class
├── Foo.class
├── Foo.java
├── Main.class
└── Main.java
0 directories, 5 files
$> cat Foo.java
public class Foo {
public class Bar {
void run() {
System.out.println("It complies.");
}
}
}
$> cat Main.java
public class Main {
public static void main(String[] args) {
Foo foo = new Foo();
Foo.Bar bar = foo.new Bar();
bar.run();
}
}
$> java Main
It complies.
Is that OpenJDK 14? I compile on JDK 8, which is what we keep as a baseline. This is a new feature then. Please update the issue accordingly.
Also, shouldn't it be like this?
Foo.Bar example2 = new example1.Bar(); // <----
See https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html , section "Inner Classes".
To instantiate an inner class, you must first instantiate the outer class. Then, create the inner object within the outer object with this syntax:
OuterClass.InnerClass innerObject = outerObject.new InnerClass()
It's strange, and I don't know why new example1.Bar()
compiles for you. It doesn't compiles for me, with either JDK 8 or 14.
$> `java_home -v 1.8`/bin/javac Main.java
Main.java:4: error: package example1 does not exist
Foo.Bar example2 = new example1.Bar();
^
1 error
$> `java_home -v 14`/bin/javac Main.java
Main.java:4: error: package example1 does not exist
Foo.Bar example2 = new example1.Bar();
^
1 error
Yeah, I came up with a working example, similar to your code. Looks like a bug.
Description
creating a new instance of an inner class doesn't highlight the
new
keyword properlyinner
Steps to Reproduce
Expected behavior:
keyword
new
is correctly highlighted.Actual behavior: