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/.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/})" 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. diff --git a/index.adoc b/index.adoc index 5cb1225..7a3c80e 100644 --- a/index.adoc +++ b/index.adoc @@ -1,10 +1,11 @@ = Java 101 Loïc Ledoyen :reproducible: +:toc-title: Java 101 :listing-caption: Listing :source-highlighter: rouge :hardbreaks-option: -:toc: +:toc: left :title-page: ifndef::ci[]