From 4fff5129bec65ff6dfc397c81bc04ac7e7a61996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Ledoyen?= Date: Thu, 23 Sep 2021 14:50:13 +0200 Subject: [PATCH 1/4] Position TOC on the left --- index.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.adoc b/index.adoc index 5cb1225..1fb0893 100644 --- a/index.adoc +++ b/index.adoc @@ -4,7 +4,7 @@ Loïc Ledoyen :listing-caption: Listing :source-highlighter: rouge :hardbreaks-option: -:toc: +:toc: left :title-page: ifndef::ci[] From 8de482f9659ea13a3da811e0f3f338424eddfa7d Mon Sep 17 00:00:00 2001 From: ledoyen Date: Thu, 23 Sep 2021 15:22:26 +0200 Subject: [PATCH 2/4] Enable i18n labels (FR) --- .github/workflows/asciidoc.sh | 6 +++--- index.adoc | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/asciidoc.sh b/.github/workflows/asciidoc.sh index 766695e..0d2c72f 100755 --- a/.github/workflows/asciidoc.sh +++ b/.github/workflows/asciidoc.sh @@ -13,10 +13,10 @@ cp "${ASCIIDOCTOR_PDF_DIR}/data/themes/default-theme.yml" ${CURRENT_PATH}/themes cp -r -f "${ASCIIDOCTOR_PDF_DIR}/data/fonts/" ${CURRENT_PATH}/ echo "Rendering HTML5..." -asciidoctor -B ${CURRENT_PATH}/ -D ${CURRENT_PATH}/outputs/html/ -o index.html -a ci=ci -a imagesdir="images" -r asciidoctor-diagram index.adoc +asciidoctor -B ${CURRENT_PATH}/ -D ${CURRENT_PATH}/outputs/html/ -o index.html -a ci=ci -a imagesdir="images" -a lang=fr -r asciidoctor-diagram index.adoc echo "Rendering PDF..." -asciidoctor-pdf -B ${CURRENT_PATH}/ -D ${CURRENT_PATH}/outputs/pdf/ -o index.pdf -a ci=ci -a imagesdir="${CURRENT_PATH}/images" -a scripts@=cjk -a pdf-styledir=${CURRENT_PATH}/themes -a pdf-fontsdir=${CURRENT_PATH}/fonts -r asciidoctor-diagram index.adoc +asciidoctor-pdf -B ${CURRENT_PATH}/ -D ${CURRENT_PATH}/outputs/pdf/ -o index.pdf -a ci=ci -a imagesdir="${CURRENT_PATH}/images" -a lang=fr -a scripts@=cjk -a pdf-styledir=${CURRENT_PATH}/themes -a pdf-fontsdir=${CURRENT_PATH}/fonts -r asciidoctor-diagram index.adoc echo "Rendering EPUB..." -asciidoctor-epub3 -B ${CURRENT_PATH}/ -D ${CURRENT_PATH}/outputs/epub/ -o index.epub -r asciidoctor-diagram -a ci=ci -a imagesdir="${CURRENT_PATH}/images" index.adoc +asciidoctor-epub3 -B ${CURRENT_PATH}/ -D ${CURRENT_PATH}/outputs/epub/ -o index.epub -r asciidoctor-diagram -a ci=ci -a imagesdir="${CURRENT_PATH}/images" -a lang=fr index.adoc diff --git a/index.adoc b/index.adoc index 1fb0893..7a3c80e 100644 --- a/index.adoc +++ b/index.adoc @@ -1,6 +1,7 @@ = Java 101 Loïc Ledoyen :reproducible: +:toc-title: Java 101 :listing-caption: Listing :source-highlighter: rouge :hardbreaks-option: From 0c5cc3c420867264c031a010f8384219d066196d Mon Sep 17 00:00:00 2001 From: ledoyen Date: Thu, 23 Sep 2021 15:34:37 +0200 Subject: [PATCH 3/4] Include images in HTML output --- .github/workflows/render.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/render.yml b/.github/workflows/render.yml index 5ee6705..ea4512f 100644 --- a/.github/workflows/render.yml +++ b/.github/workflows/render.yml @@ -14,6 +14,9 @@ jobs: uses: Analog-inc/asciidoctor-action@v1.2.1 with: shellcommand: "./.github/workflows/asciidoc.sh" + - name: Copy images for HTML output + run: | + sudo cp -rv images outputs/html - name: Extract branch name shell: bash run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" From 1972704b34f19d028f0964882586229c21be4f50 Mon Sep 17 00:00:00 2001 From: ledoyen Date: Thu, 23 Sep 2021 17:00:45 +0200 Subject: [PATCH 4/4] Add instanceof pattern matching (Java 16) --- chapters/chapter-1.adoc | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/chapters/chapter-1.adoc b/chapters/chapter-1.adoc index e4ce63f..ff067bb 100644 --- a/chapters/chapter-1.adoc +++ b/chapters/chapter-1.adoc @@ -219,9 +219,31 @@ if (a instanceof ArrayList) { // ... // <1> } ---- - <1> l’execution entrera dans le bloc si l’objet pointé par la variable `a` est de type `ArrayList` ou d’un sous-type d’ `ArrayList` +Classiquement, tester le type d'une variable est suivi par un *cast* : + +[source,java] +---- +void callBarkIfPossible(Animal animal) { + if (animal instanceof Dog) { + Dog dog = (Dog) animal; // <1> + dog.bark(); + } +} +---- +<1> Ce type de *cast* est appelé *downcasting* (passage d'un type parent à un type enfant) + +A partir de Java 16 l'opérateur `instanceof` peut prendre une opérande supplémentaire afin d'obtenir directement une variable du type testé : +[source,java] +---- +void callBarkIfPossible(Animal animal) { + if (animal instanceof Dog dog) { + dog.bark(); + } +} +---- + === Nommage Le nommage a un intérêt prépondérant dans le paradigme objet où le développeur essaie d’exprimer des concepts réels.