Skip to content

Instantly share code, notes, and snippets.

@Riduidel
Created December 10, 2020 06:26
Show Gist options
  • Save Riduidel/5b6f48453524afb50b750397155320d3 to your computer and use it in GitHub Desktop.
Save Riduidel/5b6f48453524afb50b750397155320d3 to your computer and use it in GitHub Desktop.
Visitor - 1 - main simple
import java.util.Arrays;
import java.util.List;
class Feuille {
public String montrerFeuille() { return "🍃"; }
}
class Fleur {
public String afficherFleur() { return "🌺"; }
}
public class Main {
public static void main(String[] args) {
List<Object> visitables = Arrays.asList(new Feuille(), new Fleur());
for (Object v : visitables) {
if (v instanceof Feuille) {
Feuille f = (Feuille) v;
System.out.println(f.montrerFeuille());
} else if (v instanceof Fleur) {
Fleur f = (Fleur) v;
System.out.println(f.afficherFleur());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment