Une collection organisée de snippets de code pour accélérer votre développement. Parcourez, recherchez et copiez en un clic.
public class Boite<T> {
private T t;
public void ajouter(T t) {
this.t = t;
}
public T obtenir() {
return t;
}
}
public record Utilisateur(int id, String nom) {}
// Génère automatiquement constructeur, getters, equals, hashCode, toString
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MaAnnotation {
String valeur();
int nombre() default 0;
}
public enum Jour {
LUNDI, MARDI, MERCREDI, JEUDI, VENDREDI, SAMEDI, DIMANCHE
}
Object obj = "hello";
if (obj instanceof String s) {
// s est déjà casté en String
System.out.println(s.toUpperCase());
}