File tree Expand file tree Collapse file tree 2 files changed +58
-5
lines changed
src/main/java/org/java10/examples Expand file tree Collapse file tree 2 files changed +58
-5
lines changed Original file line number Diff line number Diff line change 1- # Java10Examples
1+ # Java 10 Examples
22
3- Java JEP286 examples
3+ This project shows some examples on how to use the JEP286, the Local-Variable Type Inference, implemented on Java Version 10.
4+
5+ ## Basic examples:
6+
7+ It's possible to use on primitive types:
8+
9+ ``` java
10+ var i = 10 ; // It's an int
11+ ```
12+
13+ Refer to ` org.java10.examples.BasicExample ` class.
14+
15+
16+ It's possible to use on Java API classes:
17+
18+ ``` java
19+ var hello = " Hello!" ;
20+ ```
21+
22+ Refer to ` org.java10.examples.ObjectExample ` class.
23+
24+ ## Complex example:
25+
26+ It's possible to build developed objects:
27+
28+ ``` java
29+ var Product = new Product (" Good Laptop" , 1000f , 10f );
30+ ```
31+
32+ Refer to ` org.java10.examples.ComplexObjectExample ` class.
33+
34+ ## Adding behaviour
35+
36+ It's possible to add a new method to existing class
37+
38+ ``` java
39+ var modifiedProduct = new Product (" An internet product" , 8f , 0.5f ) {
40+ public float applyInternetPrice () {
41+ return getPrice() - 1f + getTax();
42+ }
43+ };
44+ ```
45+
46+ Refer to ` org.java10.examples.ProductExample ` class.
47+
48+ ## Mixing interfaces
49+
50+ It's possible to mix interfaces.
51+
52+ ``` java
53+ var seaplane = (Navigable & Flyer ) Vehicle :: create;
54+ ```
55+
56+ Refer to ` org.java10.examples.MixinExample ` class.
Original file line number Diff line number Diff line change 77public class ObjectExample {
88
99 public static void main (String [] args ) {
10- var string = "This is a String" ;
10+ var hello = "Hello! This is an inferred String! " ;
1111
1212 var now = LocalDate .now ();
1313
@@ -25,14 +25,14 @@ public static void main(String[] args) {
2525 stringList .add ("!" );
2626
2727 System .out .println ("Printing a String: " );
28- System .out .println (string );
28+ System .out .println (hello );
2929 System .out .println ("\n Printing a formatted LocalDate: " );
3030 System .out .println (now .format (formatter ));
3131 System .out .println ("\n Printing a String List: " );
3232 System .out .println (stringList );
3333
3434 System .out .println ("\n Printing the inferred classes: " );
35- System .out .println (string .getClass ());
35+ System .out .println (hello .getClass ());
3636 System .out .println (now .getClass ());
3737 System .out .println (formatter .getClass ());
3838 System .out .println (stringList .getClass ());
You can’t perform that action at this time.
0 commit comments