Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/g-khan/java9-examples

Java 9 features example
https://github.com/g-khan/java9-examples

Last synced: 8 days ago
JSON representation

Java 9 features example

Awesome Lists containing this project

README

        

# Java 9 Features Example

## Features:
- **Private Methods in Interface:** Encapsulation is possible in interface that mean you can avoid code duplication in default methods. Also private interface methods can be *static* or *instance*.
_see_: Magician class prepareForMagic method

- **Optional Class Improvements** _see_: Spectators class
- Optional.ifPresentOrElse()
- Optional.or()

- **Immutable Collection Factory** _see_: Spectators class
- `List names = List.of("Gokhan", "Ahmet", "Ayse");`
- Cannot set null item in to List.of: `java.lang.NullPointerException`
- Cannot add new item: `UnsupportedOperationException`
- `Set names = Set.of("Gokhan", "Ahmet", "Ayse");`
- Cannot set null item in to List.of: `java.lang.NullPointerException`
- Cannot add new item: `UnsupportedOperationException`
- Cannot add duplicate item: `IllegalArgumentException`
- `Map immutableMap = Map.of("Key1", "Gokhan", "Key2", "Ahmet");`
- Cannot put new key value pair: `UnsupportedOperationException`

Example inspired by https://www.polidea.com/blog/Exploring-Java-9Private-Interface-Methods/