I recently went to a Java event, so that's a note.
jshell
Who! It's a tool that allows you to easily execute Java commands. In Ruby, there is "irb".
In Java, start Eclipse and run it? Or compile with javac and run with java? It was a lot of work.
You can check it quickly by using jshell. Like this. It is convenient to be able to store automatically with tabs.
D:\Program Files>jshell
|Welcome to JShell--Version 13
|For an overview, type:: /help intro
jshell> System
Signature:
java.lang.System
<Press the tab again to view the document>
jshell> System.out.p
print( printf( println(
jshell> System.out.println("Hello World!!");
Hello World!!
jshell>
By the way, it is a function installed from Java9. I should have known earlier. ..
var
It's a feature from Java 10. I knew it, but I didn't use it by mistake.
I thought it was a var like javascript. In short, is it a type that does not have "type guarantee"? ..
When I heard the story at the event, it was different.
In short, you can set "numerical value" to "var variable" with "String" set! I thought, I got an error properly.
jshell> var testVal = "test data";
testVal ==> "test data"
jshell> testVal = 1;
|error:
|Incompatible type:int java.lang.Cannot convert to String:
| testVal = 1;
| ^
jshell>
This story was the most eye-opening.
jshell> class Customer {
...> void test(){
...> System.out.println("Hello World");
...> }
...> }
|Created the following:Class Customer
jshell> Customer customer = new Customer();
customer ==> Customer@5025a98f
jshell>
I wrote it like this and wrote "customer" three times in the form of "Customer customer = new Customer ();". Some people want to see "Customer cu = new Customer ();" and omit the variable name. I would like to stop this because it reduces readability.
So, I thought of "var".
jshell> var customer = new Customer();
customer ==> Customer@20322d26
jshell>
In the form of "var customer = new Customer ();", I was able to reduce "customer" to 2 times without omitting the variable name! In short, you don't have to omit the variable name and write what you have written repeatedly.
This is the purpose of the person who thought about "var".
It was a scale from my eyes. From now on, we will use "var".
Recommended Posts