## EX06 - Scenario2

Moderatoren: pmueller, SE - Design and Construction

UdoWeber
Endlosschleifenbastler
Beiträge: 156
Registriert: 8. Nov 2009 15:13

### EX06 - Scenario2

I think @ViolatingValueFactory and the static method must be above/in class Stack not class Map[...}, right?

Code: Alles auswählen

public static XXX violatingValue() { return XXX; }
@ViolatingValueFactory(name="violatingValue") // has to annotate (it at all) "push"
public void push(V v) { ... }
class Map {...}

UdoWeber
Endlosschleifenbastler
Beiträge: 156
Registriert: 8. Nov 2009 15:13

### Re: EX06 - Scenario2

So I didn't get the task at all

What I understand, we have some code like:

Code: Alles auswählen


Stack<Integer> stack = new Stack<Integer>();
stack.push(new Integer(5));

that worked with the allready given push method.

Then the developer adds a method push to the class Stack like this:

Code: Alles auswählen

public void push(Stack<V> s) {
// TODO Implement
}
Now I need to find a value for "stack.push(new Integer(5));" that will no longer compile the method call, but did before adding the additional push, did I get this right?

Thanks for help, Udo

nknauber
Erstie
Beiträge: 11
Registriert: 25. Apr 2018 16:48

### Re: EX06 - Scenario2

+1

EDIT: Also: the annotation ViolatingValueFactory only has a parameter named 'value' and not 'name'. Furthermore, if I specify a method that runs into the mentioned error by calling push, the package cannot be compiled anymore, as this is a CompileTimeError. Should we still implement such a method and submit a "non-compilable" project?

UdoWeber
Endlosschleifenbastler
Beiträge: 156
Registriert: 8. Nov 2009 15:13

### Re: EX06 - Scenario2

As far as I understand it, you just need to add the method.

Code: Alles auswählen

public static XXX violatingValue() { return XXX; }

And the annotation

Code: Alles auswählen

@ViolatingValueFactory
You should not implement the push method, just think about what happens if you do so.

Code: Alles auswählen

public void push(Stack<V> s) {
// TODO Implement
}


pmueller
Moderator
Beiträge: 87
Registriert: 25. Jan 2018 11:14

### Re: EX06 - Scenario2

Hi,
UdoWeber hat geschrieben:
12. Jun 2018 16:53
You should not implement the push method, just think about what happens if you do so.
Correct.
nknauber hat geschrieben:
12. Jun 2018 14:44
EDIT: Also: the annotation ViolatingValueFactory only has a parameter named 'value' and not 'name'.
UdoWeber hat geschrieben:
11. Jun 2018 15:09
I think @ViolatingValueFactory and the static method must be above/in class Stack not class Map[...}, right?
Yes.

As a hint: What can result from the fact that there are two methods with the same name that only differ in one (non-primitive) parameter type in the class Stack?

Best,
Patrick