diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 4c6fa5f..a2b6fb8 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -12,7 +12,38 @@ - [Tour of Scala](./examples/tour_of_scala.md) - [tutorialspoint](./examples/tutorialspoint.md) - [tutorialspoint paid course](./examples/tutorialspoint_paid.md) - - [w3schools](./examples/w3schools.md) --> + - [w3schools](./examples/w3schools.md) + +Project ideas: + calorie tracker + tic tac toe + chess + go + CSV + image stuff with the PPM format + + swing game - maybe have a simplified game engine + + fixed time loop game + + opengl/ffm + +version control + +something with statistics +newton raphston + +airplane physics program +ball throw physics program +chemical stuff + +(after bytes) Make an audio file. Play hot cross buns. + +snake +2048 +colors +battleship +--> # Modern Java diff --git a/src/collections/factories.md b/src/collections/factories.md index 9ec9e60..0405515 100644 --- a/src/collections/factories.md +++ b/src/collections/factories.md @@ -62,6 +62,7 @@ class Main { } ``` + If you want the opposite - if you want to make a copy of something like an `ArrayList` which does not support `.add`, `.remove`, etc. - you can use `copyOf`. diff --git a/src/encapsulation/classes.md b/src/encapsulation/classes.md index 64408c7..d1a53df 100644 --- a/src/encapsulation/classes.md +++ b/src/encapsulation/classes.md @@ -52,6 +52,7 @@ public class ArrayList extends AbstractList } ``` + People who write programs that depend on calling `.add` on an `ArrayList` do not need to understand how or when the internal `elementData` and `size` fields are updated. Those also need not be the only fields that exist. All that is required is "calling `.add` will add an element to the list." diff --git a/src/hash_maps/appropriate_keys.md b/src/hash_maps/appropriate_keys.md index 19ca9cf..310773b 100644 --- a/src/hash_maps/appropriate_keys.md +++ b/src/hash_maps/appropriate_keys.md @@ -3,7 +3,8 @@ Both objects with reference based and value based definitions of `equals` and `hashCode` are "appropriate" to use as keys in `HashMap`s. -The most important thing to be careful of is using objects where`equals` and `hashCode` + +The most important thing to be careful of is using objects where `equals` and `hashCode` are value based, but the object itself is mutable. ```java diff --git a/src/hash_maps/value_based_identity.md b/src/hash_maps/value_based_identity.md index f53e718..b9a53fa 100644 --- a/src/hash_maps/value_based_identity.md +++ b/src/hash_maps/value_based_identity.md @@ -1,5 +1,6 @@ # Value Based Identity + While reference based identity can be useful, it's often not what you want for keys in a `HashMap`. Ideally if you are looking up `"Tow Mater"` you shouldn't have to be careful to ensure it's the *same* instance of `String`, all you care about is that it contains the right characters. diff --git a/src/interfaces_ii.md b/src/interfaces_ii.md index 129b3af..c38bc22 100644 --- a/src/interfaces_ii.md +++ b/src/interfaces_ii.md @@ -3,5 +3,6 @@ Interfaces let you describe a common set of methods shared by different implementing classes. + They can do slightly more than this though and it's helpful to know about. \ No newline at end of file diff --git a/src/switch/exhaustiveness.md b/src/switch/exhaustiveness.md index ac79cfb..829e771 100644 --- a/src/switch/exhaustiveness.md +++ b/src/switch/exhaustiveness.md @@ -23,10 +23,36 @@ String describe(int number) { } ``` -When you have something like an enum you don't need a `default` case -because you can handle every variant explicitly. +When you have something like an enum you might think you don't need a `default` case +because you can handle every variant explicitly.[^sometimes] -```java,no_run +```java,no_run,does_not_compile +enum Bird { + TURKEY, + EAGLE, + WOODPECKER +} + +boolean isScary(Bird bird) { + switch (bird) { + case TURKEY -> { + return true; + } + case EAGLE -> { + return true; + } + case WOODPECKER -> { + return false; + } + } +} +``` + +This is, unfortunately, not the case for a switch statement. +You either need a `default` case or to have an explicit `case null` to handle the +possibility that the enum value is `null`.[^lies] + +```java,no_run,does_not_compile enum Bird { TURKEY, EAGLE, @@ -44,6 +70,17 @@ boolean isScary(Bird bird) { case WOODPECKER -> { return false; } + // Need to handle the possibility of null + // or give a "default ->" + case null -> { + // You might want to return a value or just crash + return false; + } } } -``` \ No newline at end of file +``` + +[^sometimes]: This is sometimes the case! It is really just this specific form of switch that has this restriction. + +[^lies]: Remember at the very start when I said I was going to lie to you? This is one of those lies. The real reason for this restriction has to do with how Java compiles switch statements and a concept called "separate compilation." Basically +even though we know you covered all the enum variants, Java still makes you account for if a new enum variant was added later on. It doesn't do this for all forms of `switch` though. \ No newline at end of file diff --git a/theme/book.js b/theme/book.js index 60cfba1..24a6c55 100644 --- a/theme/book.js +++ b/theme/book.js @@ -115,10 +115,10 @@ function playground_text(playground, hidden = true) { let text = playground_text(code_block); var params = { - release: '22', + release: '25', runtime: 'latest', action: 'run', - preview: true, + preview: false, code: text, };