• Keine Ergebnisse gefunden

Advanced Aspects of Object-Oriented Programming (SS 2011) Practice Sheet 5

N/A
N/A
Protected

Academic year: 2022

Aktie "Advanced Aspects of Object-Oriented Programming (SS 2011) Practice Sheet 5"

Copied!
2
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Prof. Dr. A. Poetzsch-Heffter Dipl.-Inform. Kathrin Geilmann

University of Kaiserslautern Department of Computer Science Software Technology Group

Advanced Aspects of Object-Oriented Programming (SS 2011) Practice Sheet 5

Date of Issue: 10.05.11

Deadline: 17.05.11 (until 10 a.m. as PDF via E-Mail)

Exercise 1 Questions

a) Add one or more questions to the document athttp://bit.ly/lGbs2v.

Exercise 2 StoJas Extension (postponed from Sheet 4)

In this exercise, we are going to build extensions to the Java subsetStoJasthat was presented in the lecture.

a) Extend the syntax as well as the semantics (static & dynamic) ofStoJasto support a "for(...) { ... }" statement and give a detailed explanation for the necessary adjustments.

b) Extend the syntax as well as the semantics (static & dynamic) of StooJasto support static methods and give a detailed explanation for the necessary adjustments.

c) Extend the syntax as well as the semantics (static & dynamic) ofStooJasto support static variables and give a detailed explanation for the necessary adjustments.

Exercise 3 Covariance & Contravariance

a) Discuss the concept of Java’sChecked Exceptionswith respect to covariance and contravariance.

b) Which kind of guarantee is given byChecked Exceptions?

Exercise 4 Generics

a) Write a generic static method flip which takes an object of class Pair (see the slides of the lecture) and flips the elements of thegivenPairobject.Hint: In order to flip the elements, both need to be of the same type.

b) Write a methodequalswhich only allows to compare two objects using thecompareToMethod of theComparableinterface.

c) What is the difference between a Collection<?>and aCollection<Object>? d) Explain the output of the following program:

p u b l i c f i n a l c l a s s G e n e r i c C l a s s<T> {

p u b l i c v o i d o v e r l o a d e d M e t h o d ( C o l l e c t i o n<?> o ) {

S y s t e m . o u t . p r i n t l n ( " o v e r l o a d e d M e t h o d( C o l l e c t i o n<?>) " ) ; }

p u b l i c v o i d o v e r l o a d e d M e t h o d ( L i s t<Number> s ) {

S y s t e m . o u t . p r i n t l n ( " o v e r l o a d e d M e t h o d( L i s t<Number>) " ) ; }

p u b l i c v o i d o v e r l o a d e d M e t h o d ( A r r a y L i s t<I n t e g e r> i ) {

S y s t e m . o u t . p r i n t l n ( " o v e r l o a d e d M e t h o d( A r r a y L i s t<I n t e g e r>) " ) ; }

p r i v a t e v o i d method ( L i s t<T> t ) {

o v e r l o a d e d M e t h o d ( t ) ; / / w h i c h m e t h o d i s c a l l e d ? }

p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ) {

G e n e r i c C l a s s <I n t e g e r> t e s t = new G e n e r i c C l a s s<I n t e g e r>( ) ; t e s t . method (new A r r a y L i s t<I n t e g e r>( ) ) ;

} }

(2)

e) The interface Collection<T>contains a generic method to convert a collection into an array. The method has the signature<T>T[] toArray(T[] a).

What is the purpose of the parametera? Is it possible to write a method with the same behavior with the signature

<T>T[] toArray ()? Justify your answer.

Referenzen

ÄHNLICHE DOKUMENTE

Refine the behavior of the getChar() method such that it returns the next character of the string if the position is not at the end and that it returns -1 if the reader is at the end

b) If the set of types / roles can be given at compile time and it will not change for an object during its lifecycle, it is usually a good idea to use subtyping and, if

b) Implement a StringReader. First add an interface equivalent to the BlankReader including the specification of the behavior. Second add an implementation of StringReader that

b) If the set of types / roles can be given at compile time and it will not change for an object during its lifecycle, it is usually a good idea to use subtyping and, if

a) Write a generic static method flip which takes an object of class Pair (see the slides of the lecture) and flips the elements of the given Pair object. Hint: In order to flip

• Guarantees of the type system cannot be used anymore.. b) If the set of types/roles can be given at compile time and it will not change for an object during its lifecycle, it

a) Extend the syntax as well as the semantics (static &amp; dynamic) of StoJas to support a &#34; for (...) { ... } &#34; statement and give a detailed explanation for the

Examine the code, available with this practice sheet on the web, with respect to confinedness. The classes ProofTreeNodeIt und ProofContainer should provide the externally