Last active
April 28, 2021 06:51
-
-
Save entrofi/c0354332f46a337c7e343cd92959a6da to your computer and use it in GitHub Desktop.
Java 10 Developer Features
This file contains hidden or 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
var order = new Order(); // order type is inferred | |
public List<Order> getCustomerOrders(String customerId){...} | |
var orderList = getCustomerOrders("1234"); //List of orders is inferred |
This file contains hidden or 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
var stringArray = new String[11]; | |
Arrays.fill(new String[11], 0, 10, "String Array"); | |
for(var stringInArray: stringArray) { //stringInArray is inferred from stringArray | |
System.out.println(stringInArray); | |
} |
This file contains hidden or 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
public class var { | |
} | |
//Build output | |
java: 'var' not allowed here | |
as of release 10, 'var' is a restricted type name and cannot be used for type declarations |
This file contains hidden or 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
//var as a method name is allowed | |
public void var() { | |
System.out.println("Hello var!"); | |
} | |
public void someMethod() { | |
//var as a variable name is allowed | |
var var = 3; | |
} | |
public class AClass { | |
//var as field name is allowed | |
public int var; | |
} | |
//package name is allowed | |
package var; |
This file contains hidden or 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
void someMethod() { | |
Map<String, List<Order>> orderMap = new HashMap<>(); | |
} | |
//Can now be written as | |
void someMethod() { | |
var orderMap = new HashMap<String, List<Order>>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment