-
9
pages
-
Français
-
Documents
Description
La genericite en Java (suite)F. Barthelemy14 mars 20061 Rappel : exemple simpleclass Listefboolean estVide ()freturn true ;gListe suite ()throws ListeVideException fthrow ListeVideException . exc ;gT tete ( ) throws ListeVideException fthrow ListeVideException . exc ;ggclass ListeNonVide extends ListefT premier ;Liste suivant ;ListeNonVide(T p , Liste s )fpremier = p ;suivant = s ;gboolean estVide ()freturn false ;gListe suite ( ) throws ListeVideException freturn suivant ;gT tete ( ) throws ListeVideException freturn premier ;ggclass ListeVideException extends Exceptionfstatic ListeVideException exc =new ListeVideException ( ) ;g1class Autrefstatic int longueur ( Liste> l )throws ListeVideException fint res = 0;while ( ! l . estVide ())fres++;l = l . suite ( ) ;greturn res ;gpublic static void main( String [ ] args )throws ListeVideException fListe l a l = new Liste();l a l = new ListeNonVide(5, l a l ) ;l a l = new ListeNonVide(7, l a l ) ;System . out . println ( longueur ( l a l ) ) ;ggclass TesteListefpublic static void main( String [ ] args )throws ListeVideException fListe l s = new Liste();l s = new ListeNonVide(" art " , l s ) ;l s = new ListeNonVide("gosh" , l s ) ;Liste l t = new Liste();l t = new ListeNonVide("jam" , l t ) ;l t = new ListeNonVide( l s . tete () , l t ...
-
Publié par
-
Langue
Français