BAEL-2472 changes after editor-review
This commit is contained in:
parent
065a6e2519
commit
9c0363e221
@ -0,0 +1,14 @@
|
||||
package org.baeldung.variable.scope.examples;
|
||||
|
||||
public class BracketScopeExample {
|
||||
|
||||
public void mathOperationExample() {
|
||||
Integer sum = 0;
|
||||
{
|
||||
Integer number = 2;
|
||||
sum = sum + number;
|
||||
}
|
||||
// compiler error, number cannot be solved as a variable
|
||||
// number++;
|
||||
}
|
||||
}
|
@ -9,7 +9,6 @@ public class ClassScopeExample {
|
||||
}
|
||||
|
||||
public void anotherExampleMethod() {
|
||||
amount--;
|
||||
Integer anotherAmount = amount + 4;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ public class LoopScopeExample {
|
||||
for (String name : listOfNames) {
|
||||
allNames = allNames + " " + name;
|
||||
}
|
||||
|
||||
// compiler error, name cannot be resolved to a variable
|
||||
// String lastNameUsed = name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -2,15 +2,12 @@ package org.baeldung.variable.scope.examples;
|
||||
|
||||
public class MethodScopeExample {
|
||||
|
||||
Integer size = 2;
|
||||
|
||||
public void methodA() {
|
||||
Integer area = 2;
|
||||
area = area + size;
|
||||
}
|
||||
|
||||
public void methodB() {
|
||||
size = size + 5;
|
||||
// compiler error, area cannot be resolved to a variable
|
||||
// area = area + 2;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -9,5 +9,4 @@ public class NestedScopesExample {
|
||||
String title = "John Doe";
|
||||
System.out.println(title);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package org.baeldung.variable.scope.examples;
|
||||
|
||||
public class OutOfScopeExample {
|
||||
|
||||
public void methodWithAVariableDeclaredInside() {
|
||||
String name = "John Doe";
|
||||
System.out.println(name);
|
||||
}
|
||||
|
||||
public void methodWithoutVariables() {
|
||||
System.out.println("Pattrick");
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user