Skip to content

Commit af89b23

Browse files
authored
Merge branch 'develop' into switch
2 parents 05dcbe9 + cf40a9e commit af89b23

File tree

11 files changed

+27
-19
lines changed

11 files changed

+27
-19
lines changed

src/annotations/elements.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@ The method should take no arguments.
2020
}
2121
```
2222

23-
And the return value needs to be one of a few built-in types like `Class`, `String`, `int`, `boolean`, etc.[^fulllist], an `enum`, or an array of one of those.
23+
And the return value needs to be one of a few built-in types like `Class`, `String`, `int`, `boolean`, etc.[^fulllist], an `enum`, another annotation interface, or an array of one of those.
2424

2525
```java,no_run,does_not_compile
2626
enum Priority {
2727
HIGH,
2828
LOW
2929
}
3030
31+
@interface Deadline {
32+
int year();
33+
int month();
34+
int day();
35+
}
36+
3137
class PersonInCharge {}
3238
3339
@interface Todo {
@@ -49,7 +55,10 @@ class PersonInCharge {}
4955
// Enums ✅
5056
Priority priority();
5157
52-
// Other Classes ❌
58+
// Other annotations ✅
59+
Deadline deadline();
60+
61+
// Other classes ❌
5362
PersonInCharge personInCharge();
5463
}
5564
```

src/class_extension/relation_to_encapsulation.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ class Airplane {
7272

7373
void bookMany(List<String> passengers) {
7474
for (var passenger : passengers) {
75-
bookOne(passenger);
75+
// Only change
76+
this.passengers.add(passenger);
7677
}
7778
}
7879
}

src/lambdas/method_references.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Main {
1717
}
1818

1919
void main() {
20-
Drummer drummer = () -> drum();
20+
Drummer drummer = () -> doDrum();
2121
drummer.drum();
2222
}
2323
}

src/modules/exports.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ package sky;
3333
// But classes within other packages of
3434
// the "reality" module can see it just fine.
3535
public class Cloud {
36-
private final YelloCarpet fabricOfExistence
36+
private final YellowCarpet fabricOfExistence
3737
= new YellowCarpet();
3838
3939
// ...

src/objects/challenges.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Broom {
3434
class Witch {
3535
Object pullFromHat() {
3636
double r = Math.random();
37-
if (Math.random() < 0.25) {
37+
if (r < 0.25) {
3838
return new Spell("Ensmallen");
3939
}
4040
else if (r < 0.5) {

src/standard_input_ii/aggregating_data.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ you can use a class.[^dto]
5555
class Person {
5656
String firstName;
5757
String lastName;
58-
59-
Person(String firstName, String lastName) {
60-
this.firstName = firstName;
61-
this.lastName = lastName;
62-
}
6358
}
6459
6560
Person askForName() {
@@ -87,7 +82,10 @@ Person askForName() {
8782
}
8883
} while (true);
8984
90-
return new Person(firstName, lastName);
85+
var person = new Person();
86+
person.firstName = firstName;
87+
person.lastName = lastName;
88+
return person;
9189
}
9290
9391
void main() {

src/standard_input_ii/delayed_assignment.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The problem with this is that Java isn't smart enough to know that you always in
1212
void main() {
1313
String name;
1414
while (true) {
15-
String name = IO.readln("What is your name? ");
15+
name = IO.readln("What is your name? ");
1616
if (name.isBlank()) {
1717
IO.println("Name cannot be blank!");
1818
continue;
@@ -31,7 +31,7 @@ To get around this you can either give an explicit default value.
3131
void main() {
3232
String name = null;
3333
while (true) {
34-
String name = IO.readln("What is your name? ");
34+
name = IO.readln("What is your name? ");
3535
if (name.isBlank()) {
3636
IO.println("Name cannot be blank!");
3737
continue;
@@ -52,7 +52,7 @@ to see that the code in the loop will run at least once.
5252
void main() {
5353
String name;
5454
do {
55-
String name = IO.readln("What is your name? ");
55+
name = IO.readln("What is your name? ");
5656
if (name.isBlank()) {
5757
IO.println("Name cannot be blank!");
5858
continue;

src/standard_input_ii/enums.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ enum StopLight {
3232
void main() {
3333
StopLight color;
3434
while (true) {
35-
String colorString = IO.readln("What color was the stoplight? ");
35+
String colorString = IO.readln("What color was the stoplight? ");
3636
try {
3737
color = StopLight.valueOf(colorString);
3838
} catch (RuntimeException e) {

src/switch_ii/challenges.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ enum NaturalEnemy {
2727
}
2828
2929
NaturalEnemy enemy(Profession p) {
30-
switch (p) {
30+
return switch (p) {
3131
case FIREFIGHTER -> {
3232
// CODE HERE
3333
};

src/time/instant.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void main() {
1313
}
1414
```
1515

16-
But if you happen to know a number milliseconds after January 1, 1970 UTC[^epoch] you
16+
But if you happen to know the number of milliseconds since January 1, 1970 0:00 UTC[^epoch], you
1717
can get an `Instant` which represents that point in time with `Instant.ofEpochMilli`.
1818

1919
```java

0 commit comments

Comments
 (0)