class LocalInstantiation { // local class in method static void foo(Object there) { class Local { { there.hashCode(); } static { //can only be instantiated from its own static context //cannot be instantiated here //not allowed to be instantiated heree //cannot be instantiated outside its static context new Local(); // should be highlighted as an error } static Runnable r = () -> { new Local(); // should be highlighted as an error }; } } // local class in lambda static Runnable foo = () -> { Object there = ""; class Local { { there.hashCode(); } static { new Local(); // should be highlighted as an error } static Runnable r = () -> { new Local(); // should be highlighted as an error }; } }; // local class in switch static Object bar = switch (foo) { case Runnable r -> { Object there = ""; class Local { { there.hashCode(); } static { new Local(); // should be highlighted as an error } static Runnable r = () -> { new Local(); // should be highlighted as an error }; } yield r; } }; // local class in instance init { Object there = ""; class Local { { there.hashCode(); } static { new Local(); // should be highlighted as an error } static Runnable r = () -> { new Local(); // should be highlighted as an error }; } } // local class in static init static { Object there = ""; class Local { { there.hashCode(); } static { new Local(); // should be highlighted as an error } static Runnable r = () -> { new Local(); // should be highlighted as an error }; } } }