text
stringlengths
253
1.07k
metadata
dict
<human>: Convert the following Java 8 code to Java 17: ```java // Java 8 code public class Main { public static void main(String[] args) { Runnable r = new Runnable() { @Override public void run() { System.out.println("Hello, Java 8!"); } }; r.run(); } } ``` <bot>: ```java // Java 17 code using lambda expressions public class Main { public static void main(String[] args) { Runnable r = () -> System.out.println("Hello, Java 17!"); r.run(); } } ```
{ "source": "unified_chip2" }
<human>: Convert the following Java 8 code using anonymous classes to Java 17 using the var keyword: ```java // Java 8 code List<String> list = new ArrayList<>(); for (String s : list) { System.out.println(s); } ``` <bot>: ```java // Java 17 code using var var list = new ArrayList<String>(); for (var s : list) { System.out.println(s); } ```
{ "source": "unified_chip2" }
<human>: Convert the following Java 8 switch statement to a Java 17 enhanced switch expression: ```java // Java 8 code int day = 3; String dayName; switch (day) { case 1: dayName = "Monday"; break; case 2: dayName = "Tuesday"; break; case 3: dayName = "Wednesday"; break; default: dayName = "Invalid day"; break; } ``` <bot>: ```java // Java 17 code using switch expression int day = 3; String dayName = switch (day) { case 1 -> "Monday"; case 2 -> "Tuesday"; case 3 -> "Wednesday"; default -> "Invalid day"; }; ```
{ "source": "unified_chip2" }
<human>: Convert the following Java 8 class to Java 17 using a record: ```java // Java 8 code public class Person { private final String name; private final int age; public Person(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public int getAge() { return age; } } ``` <bot>: ```java // Java 17 code using a record public record Person(String name, int age) {} ```
{ "source": "unified_chip2" }
<human>: Convert the following Java 8 code to Java 17 using sealed classes: ```java // Java 8 code public abstract class Shape { abstract double area(); } public class Circle extends Shape { private double radius; public Circle(double radius) { this.radius = radius; } @Override double area() { return Math.PI * radius * radius; } } public class Square extends Shape { private double side; public Square(double side) { this.side = side; } @Override double area() { return side * side; } } ``` <bot>: ```java // Java 17 code using sealed classes public sealed abstract class Shape permits Circle, Square { abstract double area(); } public final class Circle extends Shape { private double radius; public Circle(double radius) { this.radius = radius; } @Override double area() { return Math.PI * radius * radius; } } public final class Square extends Shape { private double side; public Square(double side) { this.side = side; } @Override double area() { return side * side; } } ```
{ "source": "unified_chip2" }
<human>: Convert the following Java 8 try-with-resources to Java 17: ```java // Java 8 code try (BufferedReader br = new BufferedReader(new FileReader(path))) { return br.readLine(); } ``` <bot>: ```java // Java 17 try-with-resources enhancement BufferedReader br = new BufferedReader(new FileReader(path)); try (br) { return br.readLine(); } ```
{ "source": "unified_chip2" }
<human>: Convert the following Java 8 interface with default methods to Java 17 using private interface methods: ```java // Java 8 code public interface Vehicle { default void start() { System.out.println("Vehicle is starting"); logStart(); } default void stop() { System.out.println("Vehicle is stopping"); } private void logStart() { System.out.println("Log: Vehicle started"); } } ``` <bot>: ```java // Java 17 private methods in interfaces public interface Vehicle { default void start() { System.out.println("Vehicle is starting"); logStart(); } default void stop() { System.out.println("Vehicle is stopping"); } private void logStart() { System.out.println("Log: Vehicle started"); } } ```
{ "source": "unified_chip2" }
<human>: Convert the following Java 8 CompletableFuture to Java 17: ```java // Java 8 code CompletableFuture.supplyAsync(() -> { return "Task completed"; }).thenAccept(result -> { System.out.println(result); }); ``` <bot>: ```java // Java 17 CompletableFuture with compact syntax CompletableFuture.supplyAsync(() -> "Task completed") .thenAccept(System.out::println); ```
{ "source": "unified_chip2" }
<human>: Convert the following Java 8 Stream API code to Java 17 using local variable syntax for lambda: ```java // Java 8 code List<String> list = List.of("A", "B", "C"); list.stream().filter(s -> s.equals("A")).forEach(System.out::println); ``` <bot>: ```java // Java 17 local variable syntax for lambda List<String> list = List.of("A", "B", "C"); list.stream().filter((var s) -> s.equals("A")).forEach(System.out::println); ```
{ "source": "unified_chip2" }
<human>: Convert the following Java 8 pattern matching to Java 17 using instanceof: ```java // Java 8 code Object obj = "Hello"; if (obj instanceof String) { String str = (String) obj; System.out.println(str); } ``` <bot>: ```java // Java 17 pattern matching for instanceof Object obj = "Hello"; if (obj instanceof String str) { System.out.println(str); } ```
{ "source": "unified_chip2" }
<human>: Convert the following Java 8 Map creation to Java 17 using Map.of() factory method: ```java // Java 8 code Map<String, Integer> map = new HashMap<>(); map.put("A", 1); map.put("B", 2); ``` <bot>: ```java // Java 17 Map.of() factory method Map<String, Integer> map = Map.of("A", 1, "B", 2); ```
{ "source": "unified_chip2" }
<human>: Convert the following Java 8 Arrays.asList() to Java 17 List.of(): ```java // Java 8 code List<String> list = Arrays.asList("A", "B", "C"); ``` <bot>: ```java // Java 17 List.of() factory method List<String> list = List.of("A", "B", "C"); ```
{ "source": "unified_chip2" }