• Keine Ergebnisse gefunden

Exercise2Wildcards / ReflectionintheContextofGenerics Exercise1Combinations PracticeSheet6:FortgeschritteneAspekteobjektorientierterProgrammierung(SS2008)

N/A
N/A
Protected

Academic year: 2022

Aktie "Exercise2Wildcards / ReflectionintheContextofGenerics Exercise1Combinations PracticeSheet6:FortgeschritteneAspekteobjektorientierterProgrammierung(SS2008)"

Copied!
2
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Prof. Dr. A. Poetzsch-Heffter Dipl.-Inform. Markus Reitz

Technische Universität Kaiserslautern Fachbereich Informatik AG Softwaretechnik

Practice Sheet 6: Fortgeschrittene Aspekte objektorientierter Programmierung (SS 2008)

Date of Issue: 20. Mai 2008 Deadline: 26. Mai 2008 (until 10 a.m. as PDF via E-Mail)

Exercise 1 Combinations

In exercise 3 of the previous practice sheet, aPermutatorclass had to be implemented. After having analysed the overall principle of the algorithm used by classPermutations, you should now be able to design and implement other combinatorical algorithms.

a) Implement a classCombinatorwhich provides the following features

1. For a given collection of elements implementing interfaceIterable<T>, theCombinatorclass provides an iterator that allows to gather all collections containing elements of typeT. The iterator creates a collection by selecting exactly one element from eachIterable<T>instance contained in the initial collection.

2. The implementation has to provide an usage interface as exemplified by the code fragment

L i s t<L i s t<I n t e g e r>> l i s t=new A r r a y L i s t<L i s t<I n t e g e r> >() {{

add ( a s L i s t ( 1 , 2 ) ) ; add ( a s L i s t ( 3 , 4 , 5 ) ) ; add ( a s L i s t ( 6 , 7 ) ) ; } } ;

f o r( C o l l e c t i o n<I n t e g e r> c u r r e n t : new C o m b i n a t o r<I n t e g e r>( l i s t ) ) S y s t e m . o u t . p r i n t l n ( c u r r e n t ) ;

which results in the output (or a permutation thereof)

[1, 3, 6]

[2, 3, 6]

[1, 4, 6]

[2, 4, 6]

[1, 5, 6]

[2, 5, 6]

[1, 3, 7]

[2, 3, 7]

[1, 4, 7]

[2, 4, 7]

[1, 5, 7]

[2, 5, 7]

b) Explain thetry { ... } finally { ... }idiom used within thenext()method in the source code of class Permutations. Which value is returned by the following code fragment?

. . . t r y {

r e t u r n 4 2 ; }

f i n a l l y { r e t u r n 1 7 0 1 ; }

. . .

Exercise 2 Wildcards / Reflection in the Context of Generics

a) Implement a generic static methodcopyhaving the following signature

p u b l i c s t a t i c <. . .> C o l l e c t i o n<. . .> c o p y ( C o l l e c t i o n<. . .> s o u r c e , C o l l e c t i o n<. . .> d e s t i n a t i o n )

When invoked, this method shall copy all elements from the source collection to the given destination collection.

Replace each ellipsis so your implementation provides maximum reusability without violating type correctness.

(2)

b) Because of thetype erasuretechnique, generic type information is not available for instances of generic types in case of Java. However, Java’s reflection capabilities provide a limited set of functionality to gather information concerning a generic type’s type variables, implemented generic interfaces and so on. Collect and explain the relevant concepts and methods provided by Java’s reflection API.

Referenzen

ÄHNLICHE DOKUMENTE

She is unravel- ling the mammalian genome not only to understand genome evolution but also to find answers for human health issues.. Bioinformatics is also one key to my own

0.3 M HCl by diluting concentrated HCl (Merck supra pure) 0.8 M ammonia by diluting 25% NH4OH (Fluka supra pure) 0.1M H2O2 by diluting 30% H2O2 (Merck supra pure)..

As for the conductivity sensor, the result of calibration shows that a set of coefficient for the conversion from the frequency to the conductivity decided at the time of the

The results we will prove in Section 2 are as follows: Let S&#34; denote the Stirling numbers of the second kind, i.e., the number of ways to partition an w-set into r

369/2018 includes 647 article which are structured into 10 parts divided in titles, chapters, The main areas of regulation are: the central public administration, the

Assume that an average of 4 marked exercises per EPROG exercise class yields 22.5 points and an average of 7 yields 37.5 points for the computation of your final grade (without

A code fragment showing how to iterate over the grid and to compute the volume of the domain by calculating the volume of each element is found at the bottom of the file

Our main tools – described in the next section – are the standard residual code argument (Propo- sition 2.2), the MacWilliams identities (Proposition 2.3), a result based on the