[JAVA] Check the result of generic parameter inference with JShell

You can easily check the local type inference result by var introduced in Java 10 with JShell. [^ 1] [^ 1]: / vars is a JShell command.

JShell also displays the inference results of the Generics Type Parameters section, so it may be more useful than the Java compiler (javac). (* There are individual differences)

$ jshell
|  Welcome to JShell -- Version 10
|  For an introduction type: /help intro
jshell> var as = new ArrayList<String>();
as ==> []

jshell> var ao = new ArrayList<>();
ao ==> []

jshell> var ar = new ArrayList();
ar ==> []

jshell> /vars
|    ArrayList<String> as = []
|    ArrayList<Object> ao = []
|    ArrayList ar = []
jshell> var li = List.of(1, 2);
li ==> [1, 2]

jshell> var lx = List.of(1, 2.0);
lx ==> [1, 2.0]

jshell> var ly = List.of(1, "2");
ly ==> [1, 2]

jshell> /vars
|    List<Integer> li = [1, 2]
|    List<Number&Comparable<? extends Number&Comparable<?>>> lx = [1, 2.0]
|    List<Serializable&Comparable<? extends Serializable&Comparable<?>>> ly = [1, 2]

For complex types inferred by the variables lx, ly, see Type inference and infinite type. thing.

Recommended Posts

Check the result of generic parameter inference with JShell
Check the contents of params with pry
Check the behavior of Java Intrinsic Locks with bpftrace
Check the operation of two roles with a chat application
Be sure to compare the result of Java compareTo with 0
Check the version of Cent OS
Check the migration status of rails
Filter the result of BindingResult [Spring]
Let's express the result of analyzing Java bytecode with a class diagram
Check the domain by checking the MX record of the email address with java
Get the result of POST in Java
Check the contents of the Java certificate store
Memo: [Java] Check the contents of the directory
Check the processing contents with [rails] binding.pry
About the treatment of BigDecimal (with reflection)
Format the contents of LocalDate with DateTimeFormatter
Check the version of the standard Web software.
[Java] Check the number of occurrences of characters
Check the operation of the interface through threads
A quick note on using jshell with the official Docker image of the JDK
Check the version of the JDK installed and the version of the JDK enabled
Verify the contents of the argument object with Mockito
Manage the version of Ruby itself with rbenv
Overwrite the contents of config with Spring-boot + JUnit5
The story of tuning android apps with libGDX
Let's check the feel of Spring Boot + Swagger 2.0
Calculate the similarity score of strings with JAVA
How to display the result of form input
Prepare the environment of CentOS 8 with Sakura VPS
Specify the default value with @Builder of Lombok
Measure the distance of the maze with breadth-first search
I checked the number of taxis with Ruby
I tried to check the operation of http request (Put) with Talented API Tester
[Java] The problem that true was returned as a result of comparing Integer with ==