-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from trishagee/main
- Loading branch information
Showing
8 changed files
with
66 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
java-samples/src/main/java/com/jetbrains/code/jdk22/ImplicitlyDeclaredClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
void main() { | ||
System.out.println("Hello, World!"); | ||
} |
37 changes: 37 additions & 0 deletions
37
java-samples/src/main/java/com/jetbrains/code/jdk22/UnnamedVariables.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.jetbrains.code.jdk22; | ||
|
||
import com.jetbrains.entity.Order; | ||
|
||
import java.awt.Point; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.concurrent.ArrayBlockingQueue; | ||
|
||
public class UnnamedVariables { | ||
static int suggestReplacingUnusedVariableWithUnderscore(Iterable<Order> orders) { | ||
int total = 0; | ||
for (Order order : orders) // order is unused | ||
total++; | ||
return total; | ||
} | ||
|
||
static void demoUseOfUnderscore() { | ||
var q = new ArrayBlockingQueue<Integer>(3, true, List.of(1, 2, 3)); | ||
while (q.size() >= 3) { | ||
int x = q.remove(); | ||
int y = q.remove(); | ||
int _ = q.remove(); // z is unused | ||
new Point(x, y); | ||
} | ||
} | ||
|
||
static int demoUseOfUnderscoreInException() { | ||
String s = "Some string"; | ||
try { | ||
return Integer.parseInt(s); | ||
} catch (NumberFormatException _) { | ||
System.out.println("Bad number: " + s); | ||
return 0; | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
java-samples/src/main/java/com/jetbrains/code/jdk23/PrimitiveTypesInSwitch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.jetbrains.code.jdk23; | ||
|
||
public class PrimitiveTypesInSwitch { | ||
private void type(Message x) { | ||
switch (x.getStatus()) { | ||
case 0 -> System.out.println("okay"); | ||
case 1 -> System.out.println("warning"); | ||
case 2 -> System.out.println("error"); | ||
default -> System.out.println("unknown status: " + x.getStatus()); | ||
} | ||
} | ||
|
||
private static class Message { | ||
private int status; | ||
|
||
public int getStatus() { | ||
return status; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters