@@ -185,8 +185,7 @@ A regular inner class scoped inside another class's curly braces, but outside an
185
185
same level that an instance variable is declared) is called a __ method-local inner class__ .
186
186
187
187
{% highlight java linenos %}
188
- class Outer {
189
-
188
+ class Outer {
190
189
private String x = "Outer";
191
190
192
191
void doStuff() {
@@ -198,10 +197,8 @@ class Outer {
198
197
} // close inner class method
199
198
200
199
} // close inner class definition
201
-
202
- } // close outer class method doStuff()
203
-
204
- } // close outer class
200
+ }
201
+ }
205
202
{% endhighlight %}
206
203
207
204
In the above example, ` class Inner ` is the method-local inner class. But the inner class is useless because you are never
@@ -212,8 +209,7 @@ use the inner class, you must make an instance of it somewhere within the method
212
209
The following legal code shows how to instantiate and use a method-local inner class:
213
210
214
211
{% highlight java linenos %}
215
- class Outer {
216
-
212
+ class Outer {
217
213
private String x = "Outer";
218
214
219
215
void doStuff() {
@@ -230,10 +226,8 @@ class Outer {
230
226
mi.seeOuter();
231
227
232
228
} // close inner class definition
233
-
234
- } // close outer class method doStuff()
235
-
236
- } // close outer class
229
+ }
230
+ }
237
231
{% endhighlight %}
238
232
239
233
### What a Method-Local Inner Object Can and Can't Do
@@ -268,11 +262,12 @@ class MyOuter {
268
262
class MyInner {
269
263
public void seeOuter() {
270
264
System.out.println("Outer x is " + x);
271
- System.out.println("Local var z is " + z); // won't compile, making 'z' final will solve the problem
272
- } // close inner class method
273
- } // close inner class definition
274
- } // close outer class method doStuff()
275
- } // close outer class
265
+ System.out.println("Local var z is " + z); // won't compile, making 'z' final
266
+ // will solve the problem
267
+ }
268
+ } // close method-local inner class
269
+ }
270
+ }
276
271
{% endhighlight %}
277
272
278
273
* A local class declared in a ` static ` method has access to only ` static ` members of the enclosing class, since there is no
0 commit comments