Skip to content

Commit f54ff9d

Browse files
author
Paulo Henrique Ortolan
committed
Updating documentation
1 parent 75a9e89 commit f54ff9d

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

README.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
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.

src/main/java/org/java10/examples/ObjectExample.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public 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("\nPrinting a formatted LocalDate: ");
3030
System.out.println(now.format(formatter));
3131
System.out.println("\nPrinting a String List: ");
3232
System.out.println(stringList);
3333

3434
System.out.println("\nPrinting 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());

0 commit comments

Comments
 (0)